mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 05:54:07 +01:00
Add logout in user dropdown
This commit is contained in:
parent
e45a0c4573
commit
8b266b65d2
@ -95,6 +95,8 @@ class GoogleRetrieveUserInfo(APIView):
|
|||||||
"""
|
"""
|
||||||
Retrieve user information from Google and create a user if not exists.
|
Retrieve user information from Google and create a user if not exists.
|
||||||
"""
|
"""
|
||||||
|
permission_classes = (AllowAny,)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
access_token = request.data.get("token")
|
access_token = request.data.get("token")
|
||||||
|
|
||||||
|
|||||||
@ -13,12 +13,6 @@ const App = () => {
|
|||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<NavBar/>
|
<NavBar/>
|
||||||
<nav>
|
|
||||||
<Link className={"nav-link"} to={"/"}>Home</Link>
|
|
||||||
<Link className={"nav-link"} to={"/login"}>Login</Link>
|
|
||||||
<Link className={"nav-link"} to={"/signup"}>Signup</Link>
|
|
||||||
<Link className={"nav-link"} to={"/testAuth"}>testAuth</Link>
|
|
||||||
</nav>
|
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path={"/"} render={() => <h1>This is Home page!</h1>} />
|
<Route path={"/"} render={() => <h1>This is Home page!</h1>} />
|
||||||
<Route path="/login" element={<AuthenticantionPage/>}/>
|
<Route path="/login" element={<AuthenticantionPage/>}/>
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
import IsAuthenticated from '../authentication/IsAuthenticated';
|
||||||
|
import axiosapi from '../../api/axiosapi';
|
||||||
import AppBar from '@mui/material/AppBar';
|
import AppBar from '@mui/material/AppBar';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Toolbar from '@mui/material/Toolbar';
|
import Toolbar from '@mui/material/Toolbar';
|
||||||
@ -13,6 +15,7 @@ import Button from '@mui/material/Button';
|
|||||||
import Tooltip from '@mui/material/Tooltip';
|
import Tooltip from '@mui/material/Tooltip';
|
||||||
import MenuItem from '@mui/material/MenuItem';
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
import AdbIcon from '@mui/icons-material/Adb';
|
import AdbIcon from '@mui/icons-material/Adb';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
|
||||||
const pages = {
|
const pages = {
|
||||||
TestAuth: '/testAuth',
|
TestAuth: '/testAuth',
|
||||||
@ -22,7 +25,6 @@ const settings = {
|
|||||||
Profile: '/profile',
|
Profile: '/profile',
|
||||||
Account: '/account',
|
Account: '/account',
|
||||||
Dashboard: '/dashboard',
|
Dashboard: '/dashboard',
|
||||||
Logout: '/logout',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function NavBar() {
|
function NavBar() {
|
||||||
@ -44,6 +46,14 @@ function NavBar() {
|
|||||||
setAnchorElUser(null);
|
setAnchorElUser(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isAuthenticated = IsAuthenticated();
|
||||||
|
|
||||||
|
const logout = () => {
|
||||||
|
// Log out the user, clear tokens, and navigate to the "/testAuth" route
|
||||||
|
axiosapi.apiUserLogout();
|
||||||
|
Navigate('/testAuth');
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppBar position="static">
|
<AppBar position="static">
|
||||||
<Container maxWidth="xl">
|
<Container maxWidth="xl">
|
||||||
@ -138,6 +148,7 @@ function NavBar() {
|
|||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
{isAuthenticated ? (
|
||||||
<Box sx={{ flexGrow: 0 }}>
|
<Box sx={{ flexGrow: 0 }}>
|
||||||
<Tooltip title="Open settings">
|
<Tooltip title="Open settings">
|
||||||
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
|
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
|
||||||
@ -167,8 +178,23 @@ function NavBar() {
|
|||||||
</Link>
|
</Link>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
|
<MenuItem>
|
||||||
|
<Link to={'/'} onClick={logout} className="nav-link">
|
||||||
|
<Typography textAlign="center">Logout</Typography>
|
||||||
|
</Link>
|
||||||
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
</Box>
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Stack direction="row" spacing={2}>
|
||||||
|
<Button variant="contained" href="/login" color="secondary">
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
<Button variant="contained" href="/signup" color="secondary">
|
||||||
|
Sign Up
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</Container>
|
</Container>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import axiosapi from './axiosapi';
|
import axiosapi from '../../api/axiosapi';
|
||||||
|
|
||||||
function IsAuthenticated() {
|
function IsAuthenticated() {
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user