diff --git a/app/components/App.tsx b/app/components/App.tsx index 6c165b8..286a31d 100644 --- a/app/components/App.tsx +++ b/app/components/App.tsx @@ -31,7 +31,7 @@ export default function App() { return ( - + ); diff --git a/app/pages/LogoutPage.tsx b/app/pages/LogoutPage.tsx new file mode 100644 index 0000000..e8f0420 --- /dev/null +++ b/app/pages/LogoutPage.tsx @@ -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 ( + + ); + } + + return ( + {consumeState} + ); +} diff --git a/app/pages/index.tsx b/app/pages/index.tsx index fd3d5ac..c530c26 100644 --- a/app/pages/index.tsx +++ b/app/pages/index.tsx @@ -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 ( diff --git a/app/state/TokenStore.ts b/app/state/TokenStore.ts index fff44cc..1432d9c 100644 --- a/app/state/TokenStore.ts +++ b/app/state/TokenStore.ts @@ -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())); }