diff --git a/src/features/login/components/LoggedInComponent.js b/src/features/login/components/LoggedInComponent.js
new file mode 100644
index 0000000..bfb51f4
--- /dev/null
+++ b/src/features/login/components/LoggedInComponent.js
@@ -0,0 +1,80 @@
+import React from "react";
+import { makeStyles } from "@material-ui/core/styles";
+import Card from "@material-ui/core/Card";
+import CardHeader from "@material-ui/core/CardHeader";
+import CardContent from "@material-ui/core/CardContent";
+import CardActions from "@material-ui/core/CardActions";
+import { Avatar, Collapse, Tooltip, Divider } from "@material-ui/core";
+import IconButton from "@material-ui/core/IconButton";
+import { AccountBox, RotateLeft, ExitToApp } from "@material-ui/icons";
+import LoginComponent from "./LoginComponent";
+import { useTranslation } from "react-i18next";
+
+const useStyles = makeStyles(theme => ({
+ root: {
+ minWidth: 350
+ },
+ onRight: {
+ marginLeft: "auto"
+ },
+ avatar: {
+ backgroundColor: theme.palette.primary.main
+ }
+}));
+
+const LoggedInComponent = ({ credentials, onChange, onLogin, onLogout }) => {
+ const classes = useStyles();
+ const { t } = useTranslation();
+ const [expanded, setExpanded] = React.useState(false);
+
+ const handleExpandLogin = () => {
+ setExpanded(!expanded);
+ };
+
+ return (
+
+
+
+
+ }
+ title={{t("Server.ActiveSession")}}
+ subheader="September 14, 2016"
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+LoggedInComponent.propTypes = {};
+
+export default LoggedInComponent;
diff --git a/src/features/login/components/LoginCard.js b/src/features/login/components/LoginCard.js
new file mode 100644
index 0000000..50b817f
--- /dev/null
+++ b/src/features/login/components/LoginCard.js
@@ -0,0 +1,25 @@
+import React from "react";
+import PropTypes from "prop-types";
+import { Card } from "@material-ui/core";
+
+import LoginComponent from "./LoginComponent";
+
+const LoginCard = ({ credentials, onChange, onLogin }) => {
+ return (
+
+
+
+ );
+};
+
+LoginCard.propTypes = {
+ credentials: PropTypes.object.isRequired,
+ onChange: PropTypes.func.isRequired,
+ onLogin: PropTypes.func.isRequired
+};
+
+export default LoginCard;
diff --git a/src/features/login/components/LoginComponent.js b/src/features/login/components/LoginComponent.js
index 3e451d2..398d3b2 100644
--- a/src/features/login/components/LoginComponent.js
+++ b/src/features/login/components/LoginComponent.js
@@ -5,7 +5,6 @@ import {
TextField,
InputAdornment,
Button,
- Card,
CardActions,
CardContent
} from "@material-ui/core";
@@ -17,6 +16,9 @@ const useStyles = makeStyles(theme => ({
field: {
margin: theme.spacing(1),
width: "300px"
+ },
+ onRight: {
+ marginLeft: "auto"
}
}));
@@ -25,7 +27,7 @@ const LoginComponent = ({ credentials, onChange, onLogin }) => {
const { t } = useTranslation();
return (
-
+ <>
{
/>
-
-
+ >
);
};
diff --git a/src/features/login/components/LoginContainer.js b/src/features/login/components/LoginContainer.js
index c2a33d7..b589cb2 100644
--- a/src/features/login/components/LoginContainer.js
+++ b/src/features/login/components/LoginContainer.js
@@ -1,18 +1,20 @@
import React, { useContext } from "react";
-import LoginComponent from "./LoginComponent";
-import { authenticate } from "../../../utils/identity";
+import LoginCard from "./LoginCard";
+import { authenticate, invalidate } from "../../../utils/identity";
import {
ApplicationStateContext,
ApplicationDispatchContext
} from "../../../state/ApplicationContexts";
-import { useToast } from "../../../hooks";
+import { useToast, useAuthorizationToken } from "../../../hooks";
import { useTranslation } from "react-i18next";
+import LoggedInComponent from "./LoggedInComponent";
const LoginContainer = () => {
const state = useContext(ApplicationStateContext);
const dispatchActions = useContext(ApplicationDispatchContext);
const { error } = useToast();
const { t } = useTranslation();
+ const { tokenIsValid } = useAuthorizationToken();
const handleChange = prop => event => {
dispatchActions.onCredentialsChange(prop, event.target.value);
@@ -33,13 +35,26 @@ const LoginContainer = () => {
}
};
+ const handleLogout = () => {
+ invalidate();
+ };
+
return (
<>
-
+ {tokenIsValid ? (
+
+ ) : (
+
+ )}
>
);
};
diff --git a/src/hooks/useAuthorizationToken.js b/src/hooks/useAuthorizationToken.js
index ee97a0b..25da53a 100644
--- a/src/hooks/useAuthorizationToken.js
+++ b/src/hooks/useAuthorizationToken.js
@@ -5,7 +5,7 @@ export const useAuthorizationToken = () => {
const state = useContext(ApplicationStateContext);
const getToken = () => state.security.authorization.token;
- const tokenIsValid = () => {
+ const validateToken = () => {
const token = getToken();
if (!token) {
return false;
@@ -15,5 +15,6 @@ export const useAuthorizationToken = () => {
return valid;
};
- return { getToken, tokenIsValid };
+ const tokenIsValid = validateToken();
+ return { getToken, validateToken, tokenIsValid };
};
diff --git a/src/utils/identity.js b/src/utils/identity.js
index f7e105f..37c5446 100644
--- a/src/utils/identity.js
+++ b/src/utils/identity.js
@@ -1,5 +1,5 @@
import { request } from "./axios";
-import { setItem } from "./localStorage";
+import { setItem, getItem, removeItem } from "./localStorage";
const storageKeys = {
TOKEN: "AUTHORIZATION_TOKEN"
@@ -22,4 +22,11 @@ const authenticate = async (username, password) => {
return response;
};
-export { storageKeys, authenticate };
+const invalidate = () => {
+ const token = getItem(storageKeys.TOKEN);
+ if (token) {
+ removeItem(storageKeys.TOKEN);
+ }
+};
+
+export { storageKeys, authenticate, invalidate };