frontend/pages/api/auth/email-confirmation.tsx (view raw)
1import type {NextApiRequest, NextApiResponse} from 'next';
2
3export default async function handler(
4 req: NextApiRequest,
5 res: NextApiResponse
6) {
7 const confirmation = req.query.confirmation;
8
9 try {
10 const response = await fetch(
11 `http://localhost:1337/api/auth/email-confirmation?confirmation=${confirmation}`
12 );
13 if (response.redirected)
14 return res.redirect(302, '/auth/login?confirmed=true');
15 const result = await response.json();
16 if (result.error) throw new Error(result.error.name);
17 } catch (error) {
18 console.error(error);
19 return res.redirect(302, '/auth/email-confirmation');
20 }
21}