feat: user activation and emails
This commit is contained in:
6
utils/apiResponse.ts
Normal file
6
utils/apiResponse.ts
Normal 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
24
utils/sender.ts
Normal 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
28
utils/types.ts
Normal 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
3
utils/urls.ts
Normal 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`;
|
||||
Reference in New Issue
Block a user