mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
feat: support logout flow (closes #85)
This commit is contained in:
parent
9cdefefbcc
commit
3fe3cfc21f
2 changed files with 56 additions and 1 deletions
|
@ -16,7 +16,7 @@ router.addFallback('root', () => {
|
||||||
router.add('GET', 'bot-join', BotJoin);
|
router.add('GET', 'bot-join', BotJoin);
|
||||||
router.add('GET', 'login-bounce', LoginBounce);
|
router.add('GET', 'login-bounce', LoginBounce);
|
||||||
router.add('GET', 'login-callback', LoginCallback);
|
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-session', GetSession);
|
||||||
router.add('GET', 'get-slug', GetSlug);
|
router.add('GET', 'get-slug', GetSlug);
|
||||||
router.add('GET', 'get-picker-data', GetPickerData);
|
router.add('GET', 'get-picker-data', GetPickerData);
|
||||||
|
|
55
src/pages/machinery/logout.tsx
Normal file
55
src/pages/machinery/logout.tsx
Normal file
|
@ -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 (
|
||||||
|
<AppShell>
|
||||||
|
<Hero>
|
||||||
|
<AccentTitle>Logging you out...</AccentTitle>
|
||||||
|
</Hero>
|
||||||
|
</AppShell>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
Loading…
Add table
Reference in a new issue