mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Refactor BeerPostHeader, refactor login and register
- Updated BeerPostHeader in /id page to use semantic HTML tags - Removed the getServerSidesProps fn in /login and /register. Moved the redirect logic over to the client, will redirect on the client side. - Added delete BeerPost option on the edit page.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user