mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
feat(auth/login): Login page will set a sessionStorage redirect flag when given an ?r= ID
Also adds HTML titles Signed-off-by: Katalina Okano <git@kat.cafe>
This commit is contained in:
parent
25ce18b911
commit
779095386d
1 changed files with 48 additions and 6 deletions
|
@ -1,22 +1,64 @@
|
|||
import { GetServerSideProps } from 'next';
|
||||
import getConfig from 'next/config';
|
||||
import Head from 'next/head';
|
||||
import * as React from 'react';
|
||||
import { GuildSlug } from 'roleypoly/common/types';
|
||||
import { apiFetch } from 'roleypoly/common/utils/isomorphicFetch';
|
||||
import { AuthLogin } from 'roleypoly/design-system/templates/auth-login';
|
||||
|
||||
const loginPage = (props: { apiURI: string }) => {
|
||||
const loginPage = (props: { apiURI: string; guildSlug?: GuildSlug }) => {
|
||||
React.useEffect(() => {
|
||||
if (props.guildSlug) {
|
||||
sessionStorage.setItem('redirectAfterNewSession', `/s/${props.guildSlug.id}`);
|
||||
}
|
||||
}, [props.guildSlug]);
|
||||
|
||||
return (
|
||||
<AuthLogin
|
||||
onSendSecretCode={() => {}}
|
||||
discordOAuthLink={`${props.apiURI}/login-bounce`}
|
||||
/>
|
||||
<>
|
||||
<Head>
|
||||
<title>
|
||||
{props.guildSlug
|
||||
? `Logging into ${props.guildSlug.name}... - Roleypoly`
|
||||
: `Logging in... - Roleypoly`}
|
||||
</title>
|
||||
</Head>
|
||||
<AuthLogin
|
||||
onSendSecretCode={() => 0}
|
||||
discordOAuthLink={`${props.apiURI}/login-bounce`}
|
||||
guildSlug={props.guildSlug}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default loginPage;
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async () => {
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const { publicRuntimeConfig } = getConfig();
|
||||
|
||||
try {
|
||||
const guildID = context.query['r'];
|
||||
console.log({ guildID });
|
||||
if (guildID) {
|
||||
const guildSlug = await apiFetch<GuildSlug>(
|
||||
`/get-slug/${guildID}`,
|
||||
{},
|
||||
context as any
|
||||
);
|
||||
|
||||
if (guildSlug) {
|
||||
return {
|
||||
props: {
|
||||
apiURI: publicRuntimeConfig.apiPublicURI,
|
||||
guildSlug,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
apiURI: publicRuntimeConfig.apiPublicURI,
|
||||
|
|
Loading…
Add table
Reference in a new issue