mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
29 lines
859 B
TypeScript
29 lines
859 B
TypeScript
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';
|
|
|
|
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('/');
|
|
});
|
|
|
|
const handler = router.handler(NextConnectOptions);
|
|
export default handler;
|