Skip to content

Commit

Permalink
Add homepage url as redirect url for login and logout (#2197)
Browse files Browse the repository at this point in the history
* Go to home page on login

* Add homepage url as redirect url for login and logout

* remove useless import
  • Loading branch information
jadmsaadaot authored Sep 15, 2023
1 parent 4054563 commit 04523ec
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
7 changes: 1 addition & 6 deletions met-web/src/components/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import UserService from 'services/userService';
import { Grid } from '@mui/material';
import { useAppSelector } from 'hooks';
import { PrimaryButton } from 'components/common';
import { useNavigate } from 'react-router-dom';
const Login = () => {
const isLoggedIn = useAppSelector((state) => state.user.authentication.authenticated);
const navigate = useNavigate();

return (
<Grid container direction="row" justifyContent="flex-start" alignItems="flex-start" spacing={2} padding="2em">
{isLoggedIn ? (
<PrimaryButton
className="btn btn-lg btn-warning"
onClick={() => UserService.doLogout(() => navigate('/'))}
>
<PrimaryButton className="btn btn-lg btn-warning" onClick={() => UserService.doLogout()}>
Logout
</PrimaryButton>
) : (
Expand Down
2 changes: 1 addition & 1 deletion met-web/src/components/layout/Header/InternalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const InternalHeader = ({ drawerWidth = 280 }: HeaderProps) => {
sx={{
color: Palette.internalHeader.color,
}}
onClick={() => UserService.doLogout(() => navigate('/'))}
onClick={() => UserService.doLogout()}
>
Logout
</Button>
Expand Down
2 changes: 1 addition & 1 deletion met-web/src/components/layout/Header/PublicHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const PublicHeader = () => {
{translate('header.title')}
</HeaderTitle>
<When condition={isLoggedIn}>
<Button color="inherit" onClick={() => UserService.doLogout(() => navigate('/'))}>
<Button color="inherit" onClick={() => UserService.doLogout()}>
Logout
</Button>
</When>
Expand Down
10 changes: 3 additions & 7 deletions met-web/src/services/userService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import http from 'apiManager/httpRequestHandler';
import { User } from 'models/user';
import { getMembershipsByUser } from 'services/membershipService';
import { USER_ROLES } from 'services/userService/constants';
import { getBaseUrl } from 'helper';

const KeycloakData = _kc;
/**
Expand Down Expand Up @@ -84,14 +85,9 @@ const userLogout = () => {
doLogout();
};

const doLogin = KeycloakData.login;
const doLogin = () => KeycloakData.login({ redirectUri: getBaseUrl() });

const doLogout = async (navigateCallback?: () => void) => {
if (navigateCallback) {
navigateCallback();
}
await KeycloakData.logout();
};
const doLogout = async () => KeycloakData.logout({ redirectUri: getBaseUrl() });
const getToken = () => KeycloakData.token;

const isLoggedIn = () => !!KeycloakData.token;
Expand Down

0 comments on commit 04523ec

Please sign in to comment.