Merged PR 20: logout

- logout
- login style fix
master
Tudor Stanciu 2020-12-24 15:00:19 +00:00
commit 84d9fda15d
4 changed files with 24 additions and 7 deletions

View File

@ -26,7 +26,8 @@ const useStyles = makeStyles(() => ({
minHeight: "100vh", minHeight: "100vh",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
justifyContent: "center" justifyContent: "center",
alignItems: "center"
} }
})); }));

View File

@ -11,7 +11,7 @@ import LoginComponent from "./LoginComponent";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
root: { card: {
minWidth: 350 minWidth: 350
}, },
onRight: { onRight: {
@ -19,6 +19,9 @@ const useStyles = makeStyles(theme => ({
}, },
avatar: { avatar: {
backgroundColor: theme.palette.primary.main backgroundColor: theme.palette.primary.main
},
collapseContent: {
padding: 0
} }
})); }));
@ -32,7 +35,7 @@ const LoggedInComponent = ({ credentials, onChange, onLogin, onLogout }) => {
}; };
return ( return (
<Card className={classes.root}> <Card className={classes.card}>
<CardHeader <CardHeader
avatar={ avatar={
<Avatar aria-label="recipe" className={classes.avatar}> <Avatar aria-label="recipe" className={classes.avatar}>
@ -63,7 +66,10 @@ const LoggedInComponent = ({ credentials, onChange, onLogin, onLogout }) => {
</CardActions> </CardActions>
<Divider /> <Divider />
<Collapse in={expanded} timeout="auto" unmountOnExit> <Collapse in={expanded} timeout="auto" unmountOnExit>
<CardContent> <CardContent
className={classes.collapseContent}
style={{ paddingBottom: "5px" }}
>
<LoginComponent <LoginComponent
credentials={credentials} credentials={credentials}
onChange={onChange} onChange={onChange}

View File

@ -14,7 +14,7 @@ const LoginContainer = () => {
const dispatchActions = useContext(ApplicationDispatchContext); const dispatchActions = useContext(ApplicationDispatchContext);
const { error } = useToast(); const { error } = useToast();
const { t } = useTranslation(); const { t } = useTranslation();
const { tokenIsValid } = useAuthorizationToken(); const { tokenIsValid, invalidateToken } = useAuthorizationToken();
const handleChange = prop => event => { const handleChange = prop => event => {
dispatchActions.onCredentialsChange(prop, event.target.value); dispatchActions.onCredentialsChange(prop, event.target.value);
@ -37,6 +37,7 @@ const LoginContainer = () => {
const handleLogout = () => { const handleLogout = () => {
invalidate(); invalidate();
invalidateToken();
}; };
return ( return (

View File

@ -1,8 +1,12 @@
import { useContext } from "react"; import { useContext } from "react";
import { ApplicationStateContext } from "../state/ApplicationContexts"; import {
ApplicationStateContext,
ApplicationDispatchContext
} from "../state/ApplicationContexts";
export const useAuthorizationToken = () => { export const useAuthorizationToken = () => {
const state = useContext(ApplicationStateContext); const state = useContext(ApplicationStateContext);
const dispatchActions = useContext(ApplicationDispatchContext);
const getToken = () => state.security.authorization.token; const getToken = () => state.security.authorization.token;
const validateToken = () => { const validateToken = () => {
@ -16,5 +20,10 @@ export const useAuthorizationToken = () => {
}; };
const tokenIsValid = validateToken(); const tokenIsValid = validateToken();
return { getToken, validateToken, tokenIsValid };
const invalidateToken = () => {
dispatchActions.onAuthorizationTokenChange(null);
};
return { getToken, validateToken, tokenIsValid, invalidateToken };
}; };