diff --git a/src/backend-worker/index.ts b/src/backend-worker/index.ts index 3b08e53..6b2bf51 100644 --- a/src/backend-worker/index.ts +++ b/src/backend-worker/index.ts @@ -16,7 +16,7 @@ router.addFallback('root', () => { router.add('GET', 'bot-join', BotJoin); router.add('GET', 'login-bounce', LoginBounce); router.add('GET', 'login-callback', LoginCallback); -router.add('GET', 'revoke-session', RevokeSession); +router.add('POST', 'revoke-session', RevokeSession); router.add('GET', 'get-session', GetSession); router.add('GET', 'get-slug', GetSlug); router.add('GET', 'get-picker-data', GetPickerData); diff --git a/src/pages/machinery/logout.tsx b/src/pages/machinery/logout.tsx new file mode 100644 index 0000000..d85f516 --- /dev/null +++ b/src/pages/machinery/logout.tsx @@ -0,0 +1,55 @@ +import fetch from 'isomorphic-unfetch'; +import { GetServerSideProps } from 'next'; +import getConfig from 'next/config'; +import nookies from 'nookies'; +import * as React from 'react'; +import { Hero } from 'roleypoly/design-system/atoms/hero'; +import { AccentTitle } from 'roleypoly/design-system/atoms/typography'; +import { AppShell } from 'roleypoly/design-system/organisms/app-shell'; + +type Props = { + sessionID: string; +}; + +const Logout = (props: Props) => { + React.useEffect(() => { + sessionStorage.removeItem('session_key'); + location.href = '/'; + }, []); + + return ( + + + Logging you out... + + + ); +}; + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { publicRuntimeConfig } = getConfig(); + + const sessionKey = nookies.get(context)['rp_session_key']; + if (!sessionKey) { + return { props: {} }; + } + try { + await fetch(`${publicRuntimeConfig.apiPublicURI}/revoke-session`, { + method: 'POST', + headers: { + authorization: `Bearer ${sessionKey}`, + }, + }); + } catch (e) {} + + nookies.set(context, 'rp_session_key', '', { + httpOnly: true, + maxAge: 0, + path: '/', + sameSite: 'strict', + }); + + return { props: {} }; +}; + +export default Logout;