feat: user activation and emails
This commit is contained in:
42
app/api/confirmation/route.ts
Normal file
42
app/api/confirmation/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { z } from 'zod';
|
||||
import prisma from '../../../prisma/prisma';
|
||||
import { ApiResponse } from '../../../utils/apiResponse';
|
||||
import { ConfirmationSchema, ResponseSchema } from '../../../utils/types';
|
||||
|
||||
export const dynamic = 'force-dynamic'; // defaults to force-static
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validation = ConfirmationSchema.safeParse(body);
|
||||
if (!validation.success || !validation.data.code) {
|
||||
return ApiResponse(400, 'Bad request');
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
code: validation.data.code
|
||||
}
|
||||
});
|
||||
|
||||
if (user) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
code: validation.data.code
|
||||
},
|
||||
data: {
|
||||
confirmed: true
|
||||
}
|
||||
});
|
||||
|
||||
const message: z.infer<typeof ResponseSchema> = {
|
||||
message: `Thank you for confirming the subscripion!`
|
||||
};
|
||||
|
||||
return ApiResponse(200, JSON.stringify(message));
|
||||
}
|
||||
|
||||
const message: z.infer<typeof ResponseSchema> = {
|
||||
message: `Nothing to see here...`
|
||||
};
|
||||
|
||||
return ApiResponse(200, JSON.stringify(message));
|
||||
}
|
||||
Reference in New Issue
Block a user