all repos — caroster @ af1cc163f83aa7a171a4b1ee8a4ce6b095d10660

[Octree] Group carpool to your event https://caroster.io

frontend/pages/api/auth/email-confirmation.tsx (view raw)

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