Skip to content

Commit

Permalink
wip(pages/signup): redirect logged in users to profile
Browse files Browse the repository at this point in the history
Temporary fix for #181 that clears any edits on the signup page due to
SWR revalidating the global user object. Instead of allowing users to
edit their profiles directly on the org signup page, TB now just
redirects them to their profile pages.
  • Loading branch information
nicholaschiang committed May 16, 2021
1 parent 2be345f commit 7b303a2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pages/[org]/signup.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ParsedUrlQuery } from 'querystring';

import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next';
import Router, { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import useTranslation from 'next-translate/useTranslation';

import { AspectHeader, EmptyHeader } from 'components/navigation';
Expand All @@ -15,6 +15,7 @@ import { PageProps, getPageProps } from 'lib/page';
import { OrgContext } from 'lib/context/org';
import { db } from 'lib/api/firebase';
import usePage from 'lib/hooks/page';
import { useUser } from 'lib/context/user';
import { withI18n } from 'lib/intl';

import common from 'locales/en/common.json';
Expand Down Expand Up @@ -42,6 +43,18 @@ function SignupPage({ org, ...props }: SignupPageProps): JSX.Element {
});
}, [org, query]);

// Redirect to the user's profile page if they're logged in. Temporary fix for
// the revalidation problem that would clear any edits on this signup page.
// @see {@link https://github.com/tutorbookapp/tutorbook/issues/181}
const { loggedIn } = useUser();
useEffect(() => {
void Router.prefetch('/profile');
}, []);
useEffect(() => {
if (!loggedIn) return;
void Router.replace('/profile');
}, [loggedIn]);

return (
<OrgContext.Provider value={{ org: org ? Org.fromJSON(org) : undefined }}>
<Page
Expand Down

0 comments on commit 7b303a2

Please sign in to comment.