diff --git a/backend/users/views.py b/backend/users/views.py index 93e0ab0..cb63de2 100644 --- a/backend/users/views.py +++ b/backend/users/views.py @@ -95,6 +95,8 @@ class GoogleRetrieveUserInfo(APIView): """ Retrieve user information from Google and create a user if not exists. """ + permission_classes = (AllowAny,) + def post(self, request): access_token = request.data.get("token") diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 0ac97eb..8c7d50d 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -13,12 +13,6 @@ const App = () => {
-

This is Home page!

} /> }/> diff --git a/frontend/src/components/Nav/Navbar.jsx b/frontend/src/components/Nav/Navbar.jsx index 93cbd08..331ab9e 100644 --- a/frontend/src/components/Nav/Navbar.jsx +++ b/frontend/src/components/Nav/Navbar.jsx @@ -1,5 +1,7 @@ import * as React from 'react'; import { Link } from 'react-router-dom'; +import IsAuthenticated from '../authentication/IsAuthenticated'; +import axiosapi from '../../api/axiosapi'; import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; import Toolbar from '@mui/material/Toolbar'; @@ -13,6 +15,7 @@ import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; import MenuItem from '@mui/material/MenuItem'; import AdbIcon from '@mui/icons-material/Adb'; +import Stack from '@mui/material/Stack'; const pages = { TestAuth: '/testAuth', @@ -22,7 +25,6 @@ const settings = { Profile: '/profile', Account: '/account', Dashboard: '/dashboard', - Logout: '/logout', }; function NavBar() { @@ -44,6 +46,14 @@ function NavBar() { setAnchorElUser(null); }; + const isAuthenticated = IsAuthenticated(); + + const logout = () => { + // Log out the user, clear tokens, and navigate to the "/testAuth" route + axiosapi.apiUserLogout(); + Navigate('/testAuth'); +} + return ( @@ -138,37 +148,53 @@ function NavBar() { ))} - + {isAuthenticated ? ( + - + - + {Object.entries(settings).map(([setting, path]) => ( - + - {setting} + {setting} - + ))} + + + Logout + + - + + ) : ( + + + + + )} diff --git a/frontend/src/components/authentication/IsAuthenticated.jsx b/frontend/src/components/authentication/IsAuthenticated.jsx index 48edd73..e3691c8 100644 --- a/frontend/src/components/authentication/IsAuthenticated.jsx +++ b/frontend/src/components/authentication/IsAuthenticated.jsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import axiosapi from './axiosapi'; +import axiosapi from '../../api/axiosapi'; function IsAuthenticated() { const [isAuthenticated, setIsAuthenticated] = useState(false);