feat: Store a session key in the browser's SessionStorage

This commit is contained in:
Alexander Polynomdivision 2018-09-06 20:22:41 +02:00
parent 423e2263dc
commit b4bc72640b
2 changed files with 26 additions and 2 deletions

View File

@ -34,12 +34,18 @@ interface IState {
drawerOpen: boolean;
}
// TODO: Replace the sessionStorage with localStorage
export default class Application extends React.Component<{}, IState> {
constructor(props: any) {
super(props);
// Load a key from the SessionStorage
const authKey = window.sessionStorage.getItem("authKey") || null;
// TODO
const loggedIn = authKey !== null;
this.state = {
loggedIn: false,
loggedIn,
drawerOpen: false,
};
@ -186,6 +192,23 @@ export default class Application extends React.Component<{}, IState> {
<Divider />
<ListItem button onClick={() => {
// Remove the auth token from the SessionStorage
window.sessionStorage.removeItem("authKey");
// Set the loggedIn State to false
this.setState({
loggedIn: false,
// In case the drawer was open
drawerOpen: false,
});
}}>
<ListItemText>
Abmelden
</ListItemText>
</ListItem>
<Divider />
<ListItem button onClick={() => window.location = "https://gitlab.com/Polynomdivision/Lateinicus/tree/master"}>
<ListItemIcon>
<InfoIcon />

View File

@ -66,7 +66,8 @@ export default class LoginPage extends React.Component<{}, IState> {
const { username, password } = this.state;
this.props.login(username, password).then((res) => {
// Don't even do anything here!
// Set the session key
window.sessionStorage.setItem("authKey", "test123");
}, (err) => {
load(false);
showSnackbar("Failed to log in");