feat: Store a session key in the browser's SessionStorage
This commit is contained in:
parent
423e2263dc
commit
b4bc72640b
@ -34,12 +34,18 @@ interface IState {
|
|||||||
drawerOpen: boolean;
|
drawerOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Replace the sessionStorage with localStorage
|
||||||
export default class Application extends React.Component<{}, IState> {
|
export default class Application extends React.Component<{}, IState> {
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
// Load a key from the SessionStorage
|
||||||
|
const authKey = window.sessionStorage.getItem("authKey") || null;
|
||||||
|
// TODO
|
||||||
|
const loggedIn = authKey !== null;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
loggedIn: false,
|
loggedIn,
|
||||||
drawerOpen: false,
|
drawerOpen: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -186,6 +192,23 @@ export default class Application extends React.Component<{}, IState> {
|
|||||||
|
|
||||||
<Divider />
|
<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"}>
|
<ListItem button onClick={() => window.location = "https://gitlab.com/Polynomdivision/Lateinicus/tree/master"}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<InfoIcon />
|
<InfoIcon />
|
||||||
|
@ -66,7 +66,8 @@ export default class LoginPage extends React.Component<{}, IState> {
|
|||||||
|
|
||||||
const { username, password } = this.state;
|
const { username, password } = this.state;
|
||||||
this.props.login(username, password).then((res) => {
|
this.props.login(username, password).then((res) => {
|
||||||
// Don't even do anything here!
|
// Set the session key
|
||||||
|
window.sessionStorage.setItem("authKey", "test123");
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
load(false);
|
load(false);
|
||||||
showSnackbar("Failed to log in");
|
showSnackbar("Failed to log in");
|
||||||
|
Reference in New Issue
Block a user