Skip to content

Commit

Permalink
fix logout in producer area
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Aug 26, 2024
1 parent 91b2f03 commit 7c8cddd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions frontend/app/src/layouts/customer/CustomerLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { AuthenticationService } from '../../authentication/service/Authenticati
import { Login, Logout } from '@mui/icons-material'
import { Navigate, Outlet, useLoaderData, useNavigate } from 'react-router-dom'
import { ApiBuilder } from '../../api/ApiBuilder.ts'
import { UrlService } from '../../domains/commons/service/UrlService.ts'


export default function CustomerLayout() {

const {keycloak} = useKeycloak()
const authenticationService = new AuthenticationService(keycloak)
const urlService = new UrlService()

const data = useLoaderData()
const data = useLoaderData()
const authenticatedAsProducer = data.authenticatedAsProducer
const customer = data.customer

Expand All @@ -25,11 +27,16 @@ export default function CustomerLayout() {
return <Navigate to='/customer/registration'/>
}

async function logout() {
const frontendUrl = await urlService.getCustomerFrontentUrl()
keycloak.logout({redirectUri: frontendUrl})
}

function displayAuthenticationButton(): React.ReactNode {
if (authenticationService.isAuthenticated()) {
return <>
<Typography>{authenticationService.getCurrentUserFirstName() } {authenticationService.getCurrentUserLastName()}</Typography>
<IconButton onClick={keycloak.logout} color="inherit">
<IconButton onClick={logout} color="inherit">
<Logout/>
</IconButton>
</>
Expand Down
10 changes: 8 additions & 2 deletions frontend/app/src/layouts/producer/AuthenticatedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {Close, Logout, Menu} from '@mui/icons-material'
import SideMenu from './SideMenu.jsx'
import { AuthenticationService } from '../../authentication/service/AuthenticationService.ts';
import { Navigate, Outlet, useLoaderData } from 'react-router-dom';
import { UrlService } from '../../domains/commons/service/UrlService.ts';


export default function AuthenticatedLayout() {
const { keycloak } = useKeycloak()
const [sideMenuOpen, setSideMenuOpen] = useState(false)
const authenticationService = new AuthenticationService(keycloak)
const urlService = new UrlService()

const authenticatedAsCustomer: boolean = useLoaderData()

Expand All @@ -31,7 +33,11 @@ export default function AuthenticatedLayout() {
return <Menu/>
}
}


async function logout() {
const frontendUrl = await urlService.getProducerFrontentUrl()
keycloak.logout({redirectUri: `${frontendUrl}/authentication`})
}

function getAuthenticatedLayout() {
return <Box sx={{ display: 'flex' }}>
Expand Down Expand Up @@ -60,7 +66,7 @@ export default function AuthenticatedLayout() {
Viande en direct
</Typography>
<Typography>{authenticationService.getCurrentUserFirstName() } {authenticationService.getCurrentUserLastName()}</Typography>
<IconButton onClick={keycloak.logout} color="inherit">
<IconButton onClick={logout} color="inherit">
<Logout/>
</IconButton>
</Toolbar>
Expand Down

0 comments on commit 7c8cddd

Please sign in to comment.