diff --git a/backend/llms/prompt_manager.py b/backend/llms/prompt_manager.py index 6983a9c..4d49ea0 100644 --- a/backend/llms/prompt_manager.py +++ b/backend/llms/prompt_manager.py @@ -105,9 +105,16 @@ def jpg_data_extraction_prompt(self, instructions: str): Example output: {{ - "client_name":"John Doe", - "invoice_amount":"1000", - "date":"01-01-2021" + {{ + "client_name":"John Doe", + "invoice_amount":"1000", + "date":"01-01-2021" + }}, + {{ + "client_name":"Jane Doe", + "invoice_amount":"2000", + "date":"01-01-2021" + }} }} In this example, the requested information would have been client name, invoice amount, and date. diff --git a/backend/routes/auth_routes.py b/backend/routes/auth_routes.py index be5b27b..eb4c0ca 100644 --- a/backend/routes/auth_routes.py +++ b/backend/routes/auth_routes.py @@ -74,6 +74,7 @@ async def login_for_access_token( detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) + if remember: access_token = create_token( {"sub": user.username}, @@ -85,7 +86,8 @@ async def login_for_access_token( ) else: access_token = create_token( - {"sub": user.username}, timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) + {"sub": user.username}, + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES), ) refresh_token = create_token( {"sub": user.username}, timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS) @@ -125,7 +127,8 @@ async def refresh_access_token( ) access_token = create_token( - {"sub": user.username}, timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) + {"sub": user.username}, + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES), ) new_refresh_token = create_token( {"sub": user.username}, timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS) @@ -198,25 +201,25 @@ async def register(response: Response, user: UserCreate): user_manager.create_user(db_user) # Generate access token - access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) access_token = create_token( - data={"sub": user.username}, expires_delta=access_token_expires + {"sub": user.username}, + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES), + ) + refresh_token = create_token( + {"sub": user.username}, timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS) ) - # Set cookie - response.set_cookie( - key="access_token", - value=f"Bearer {access_token}", - httponly=True, - max_age=1800, - secure=True, - samesite="lax", + update_user_refresh_token( + user_id=user.id, + refresh_token=refresh_token, ) + set_tokens_in_cookies(response, access_token, refresh_token) return {"message": "Registration successful"} @auth_router.post("/logout/", response_model=LogoutResponse) async def logout(response: Response): response.delete_cookie(key="access_token") + response.delete_cookie(key="refresh_token") return {"message": "Logged out successfully"} diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 43661db..02ca774 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -59,11 +59,7 @@ function App() { path="/" element={} /> - : - } - /> + } /> } /> } /> } /> diff --git a/frontend/src/components/auth/RequireAuth.jsx b/frontend/src/components/auth/RequireAuth.jsx index 13fbb37..be7d5da 100644 --- a/frontend/src/components/auth/RequireAuth.jsx +++ b/frontend/src/components/auth/RequireAuth.jsx @@ -14,6 +14,7 @@ function RequireAuth({ children }) { } if (!isEmailVerified) { + console.log("from require auth") // Redirect to the verify-email page if email is not verified return ; } diff --git a/frontend/src/contexts/AuthContext.jsx b/frontend/src/contexts/AuthContext.jsx index 68c5ef9..73310a2 100644 --- a/frontend/src/contexts/AuthContext.jsx +++ b/frontend/src/contexts/AuthContext.jsx @@ -52,10 +52,14 @@ export const AuthProvider = ({ children }) => { setIsAuthenticated(newAuthState); }; + const updateEmailVerification = (newEmailVerificationState) => { + setIsEmailVerified(newEmailVerificationState); + }; + // The Provider component from our created context is used here. // It makes the `isAuthenticated` state and `updateAuth` function available to any descendants of this component return ( - + {children} ); diff --git a/frontend/src/pages/login/LoginPage.jsx b/frontend/src/pages/login/LoginPage.jsx index eb8c5fd..cea6ad3 100644 --- a/frontend/src/pages/login/LoginPage.jsx +++ b/frontend/src/pages/login/LoginPage.jsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import axios from 'axios'; import qs from 'qs'; import { Box, Button, Checkbox, Container, FormControlLabel, TextField, Typography } from '@mui/material'; @@ -14,9 +14,10 @@ function LoginPage({ onLogin }) { const [password, setPassword] = useState(''); const [rememberMe, setRememberMe] = useState(false); const navigate = useNavigate(); - const { updateAuth } = useAuth(); + const { updateAuth, updateEmailVerification } = useAuth(); const [errorMessage, setErrorMessage] = useState(''); + const handleSubmit = async (event) => { event.preventDefault(); @@ -24,7 +25,7 @@ function LoginPage({ onLogin }) { const isEmail = validator.isEmail(usernameOrEmail); const data = isEmail ? { email: usernameOrEmail, password, remember: rememberMe } - : { username: usernameOrEmail, password, rememer: rememberMe }; + : { username: usernameOrEmail, password, remember: rememberMe }; try { const response = await axios.post(`${API_URL}token/`, qs.stringify (data), { @@ -42,8 +43,13 @@ function LoginPage({ onLogin }) { }); if (userResponse.data.requires_password_update) { navigate('/change-password'); + } else if (userResponse.data.email_verified == false) { + console.log("email_verified is false") + navigate('/verify-email'); } else { - navigate('/dashboards'); + console.log("email_verified is true") + updateEmailVerification(true); + navigate('/dashboards') } } } catch (error) {