Skip to content

Commit

Permalink
Merge branch 'main' into drag-and-drop
Browse files Browse the repository at this point in the history
  • Loading branch information
Alforoan authored Jun 13, 2024
2 parents dc881c5 + ac366d5 commit b7ae86b
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 62 deletions.
91 changes: 91 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 47 additions & 46 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
{
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "jest"
},
"dependencies": {
"@auth0/auth0-react": "^2.2.4",
"@headlessui/react": "^2.0.4",
"@hello-pangea/dnd": "^16.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1"
},
"devDependencies": {
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.66",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"babel-jest": "^29.7.0",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"jest": "^29.7.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.4",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "jest"
},
"dependencies": {
"@auth0/auth0-react": "^2.2.4",
"@headlessui/react": "^2.0.4",
"@hello-pangea/dnd": "^16.6.0",
"axios": "^1.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1"
},
"devDependencies": {
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.66",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"babel-jest": "^29.7.0",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"jest": "^29.7.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.4",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
40 changes: 40 additions & 0 deletions client/src/components/AuthHandler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useEffect } from "react";
import { useAuth0 } from "@auth0/auth0-react";
import axios from 'axios';

const AuthHandler: React.FC = () => {
const { isAuthenticated, user, getIdTokenClaims } = useAuth0();

useEffect(() => {
const handleAuthentication = async () => {
if (isAuthenticated && user) {
console.log('User is authenticated:', user);

try {
const endpoint = 'http://127.0.0.1:5000/api/signin'
console.log({endpoint});

// Send data to the backend
try {
const response = await axios.post(endpoint, {
email: user.email,
});
console.log('User data sent to backend:', response.data);
} catch (error) {
console.error('Error sending user data to backend:', error);
}
} catch (error) {
console.error('Error checking email existence:', error);
}
} else {
console.log('User not authenticated or user object not available');
}
};

handleAuthentication();
}, [isAuthenticated, user, getIdTokenClaims]);

return null;
};

export default AuthHandler;
2 changes: 1 addition & 1 deletion client/src/components/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Profile: React.FC = () => {
isAuthenticated && user ? (
<div>
<img src={user.picture} alt={user.name} />
<h2>{user.name}</h2>
<h2>{user.nickname}</h2>
<p>{user.email}</p>
</div>
) : (
Expand Down
30 changes: 15 additions & 15 deletions client/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import { Auth0Provider } from "@auth0/auth0-react";
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
import './index.css';
import { Auth0Provider } from '@auth0/auth0-react';

const domain = import.meta.env.VITE_AUTH0_DOMAIN;
const clientId = import.meta.env.VITE_AUTH0_CLIENT_ID;

ReactDOM.createRoot(document.getElementById("root")!).render(
// <React.StrictMode>
<Auth0Provider
domain={domain}
clientId={clientId}
authorizationParams={{ redirect_uri: window.location.origin }}
>
<App />
</Auth0Provider>
// </React.StrictMode>,
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<Auth0Provider
domain={domain}
clientId={clientId}
authorizationParams={{ redirect_uri: window.location.origin }}
>
<App />
</Auth0Provider>
</React.StrictMode>,
);
Binary file modified server/__pycache__/app.cpython-311.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS


app = Flask(__name__)


app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:123456@localhost:5432/flaskdb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

cors = CORS(app, resources={r"/api/*": {"origins": "*"}})

db = SQLAlchemy(app)

class Board(db.Model):
__tablename__ = 'boards'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), unique=True, nullable=False)

class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(80), unique=True, nullable=False)




@app.get('/')
def home():
return 'Hello df'

@app.route('/api/signin', methods=['POST'])
def sign_in_or_create_user():
if request.method == 'POST':
data = request.json
print('DATA FROM FRONTEND',data)
email = data.get('email')
user = User.query.filter_by(email=email).first()
if user:
return jsonify({'message': 'Sign in successful'}), 200
else:
user = User(email=email)
db.session.add(user)
db.session.commit()
return jsonify({'message': 'User created successfully'}), 201
else:
return jsonify({'error': 'Only POST requests are allowed for this endpoint'}), 405

@app.route('/api/boards', methods=['POST'])
def create_board():
if request.method == 'POST':
Expand Down

0 comments on commit b7ae86b

Please sign in to comment.