Browse Source

Added logout route and page

update-deps
Alex Mikhalev 7 years ago
parent
commit
4f0efd9551
  1. 2
      app/components/App.tsx
  2. 17
      app/pages/LogoutPage.tsx
  3. 1
      app/pages/index.tsx
  4. 6
      app/state/TokenStore.ts

2
app/components/App.tsx

@ -31,7 +31,7 @@ export default function App() { @@ -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

@ -0,0 +1,17 @@ @@ -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>
);
}

1
app/pages/index.tsx

@ -4,6 +4,7 @@ import { RouteComponentProps } from "react-router"; @@ -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 (

6
app/state/TokenStore.ts

@ -19,6 +19,12 @@ export class TokenStore { @@ -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…
Cancel
Save