mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Refactored the comments ui into various new components, added the delete beer comment by id feature.
29 lines
705 B
TypeScript
29 lines
705 B
TypeScript
import { GetServerSideProps, GetServerSidePropsContext, Redirect } from 'next';
|
|
import { getLoginSession } from '@/config/auth/session';
|
|
import findUserById from '@/services/User/findUserById';
|
|
|
|
const redirectIfLoggedIn = (redirect: Redirect) => {
|
|
const fn: GetServerSideProps = async (context: GetServerSidePropsContext) => {
|
|
try {
|
|
const { req } = context;
|
|
const session = await getLoginSession(req);
|
|
|
|
const { id } = session;
|
|
|
|
const user = await findUserById(id);
|
|
|
|
if (!user) {
|
|
throw new Error('Could not get user.');
|
|
}
|
|
|
|
return { redirect };
|
|
} catch {
|
|
return { props: {} };
|
|
}
|
|
};
|
|
|
|
return fn;
|
|
};
|
|
|
|
export default redirectIfLoggedIn;
|