Added logout route and page
This commit is contained in:
parent
efe7f745fc
commit
4f0efd9551
@ -31,7 +31,7 @@ export default function App() {
|
||||
return (
|
||||
<Switch>
|
||||
<Route path="/login" component={p.LoginPage}/>
|
||||
<Route path="/login" component={p.LoginPage}/>
|
||||
<Route path="/logout" component={p.LogoutPage}/>
|
||||
<NavContainer/>
|
||||
</Switch>
|
||||
);
|
||||
|
17
app/pages/LogoutPage.tsx
Normal file
17
app/pages/LogoutPage.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import * as React from "react";
|
||||
import { Redirect } from "react-router";
|
||||
|
||||
import { AppState, ConsumeState } from "@app/state";
|
||||
|
||||
export function LogoutPage() {
|
||||
function consumeState(appState: AppState) {
|
||||
appState.tokenStore.clear();
|
||||
return (
|
||||
<Redirect to="/" />
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ConsumeState>{consumeState}</ConsumeState>
|
||||
);
|
||||
}
|
@ -4,6 +4,7 @@ import { RouteComponentProps } from "react-router";
|
||||
import { DevicesView, MessageTest} from "@app/components";
|
||||
|
||||
export { LoginPage } from "./LoginPage";
|
||||
export { LogoutPage } from "./LogoutPage";
|
||||
|
||||
export function DevicePage({ match }: RouteComponentProps<{ deviceId: string }>) {
|
||||
return (
|
||||
|
@ -19,6 +19,12 @@ export class TokenStore {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.accessToken.token = null;
|
||||
this.refreshToken.token = null;
|
||||
this.saveLocalStorage();
|
||||
}
|
||||
|
||||
saveLocalStorage() {
|
||||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this.toJSON()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user