feat: user activation and emails

This commit is contained in:
Riccardo
2023-12-04 16:18:35 +01:00
parent 527fc25c08
commit 37f5692f61
40 changed files with 2093 additions and 310 deletions

6
utils/apiResponse.ts Normal file
View File

@@ -0,0 +1,6 @@
export function ApiResponse(status: number, message: string) {
const response = new Response(message, { status });
response.headers.set('Access-Control-Allow-Origin', process.env.HOME_URL!);
return response;
}

24
utils/sender.ts Normal file
View File

@@ -0,0 +1,24 @@
import { Resend } from 'resend';
export async function sendEmail(
to: string[],
subject: string,
template: JSX.Element
) {
const resend = new Resend(process.env.RESEND_KEY);
try {
const { error } = await resend.emails.send({
from: process.env.RESEND_FROM!,
to,
subject,
react: template,
});
if (error) {
console.log(error);
}
} catch (error) {
console.log(error);
}
}

28
utils/types.ts Normal file
View File

@@ -0,0 +1,28 @@
import { z } from 'zod';
export const ResponseSchema = z.object({
message: z.string(),
});
export const SubscribeFormSchema = z.object({
email: z.string().email(),
});
export const ConfirmationSchema = z.object({
code: z.string(),
});
export const UnsubscribeFormSchema = z.object({
email: z.string().email(),
});
export const NewsSchema = z.object({
id: z.number(),
title: z.string(),
text: z.string().optional(),
type: z.string(),
by: z.string(),
time: z.number(),
url: z.string().optional(),
score: z.number(),
});

3
utils/urls.ts Normal file
View File

@@ -0,0 +1,3 @@
export const topNews = 'https://hacker-news.firebaseio.com/v0/topstories.json';
export const singleNews = (id: number) =>
`https://hacker-news.firebaseio.com/v0/item/${id}.json`;