mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
begin extracting user controllers out of routes
This commit is contained in:
@@ -1,28 +1,16 @@
|
||||
import { getLoginSession } from '@/config/auth/session';
|
||||
import { removeTokenCookie } from '@/config/auth/cookie';
|
||||
import NextConnectOptions from '@/config/nextConnect/NextConnectOptions';
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { createRouter } from 'next-connect';
|
||||
import { z } from 'zod';
|
||||
import ServerError from '@/config/util/ServerError';
|
||||
import { logoutUser } from '@/controllers/auth';
|
||||
|
||||
const router = createRouter<
|
||||
NextApiRequest,
|
||||
NextApiResponse<z.infer<typeof APIResponseValidationSchema>>
|
||||
>();
|
||||
|
||||
router.all(async (req, res) => {
|
||||
const session = await getLoginSession(req);
|
||||
|
||||
if (!session) {
|
||||
throw new ServerError('You are not logged in.', 400);
|
||||
}
|
||||
|
||||
removeTokenCookie(res);
|
||||
|
||||
res.redirect('/');
|
||||
});
|
||||
router.all(logoutUser);
|
||||
|
||||
const handler = router.handler(NextConnectOptions);
|
||||
export default handler;
|
||||
|
||||
Reference in New Issue
Block a user