owlcub-academy/src/auth.ts

52 lines
2.2 KiB
TypeScript

import NextAuth from "next-auth";
import { PrismaAdapter } from "@auth/prisma-adapter";
import Resend from "next-auth/providers/resend";
import { db } from "@/lib/db";
export const { handlers, auth, signIn, signOut } = NextAuth({
trustHost: true,
adapter: PrismaAdapter(db),
providers: [
Resend({
from: "OwlCub Academy <noreply@owlcub.com>",
sendVerificationRequest: async ({ identifier: email, url, provider }) => {
const { Resend: ResendClient } = await import("resend");
const resend = new ResendClient(process.env.RESEND_API_KEY!);
await resend.emails.send({
from: provider.from as string,
to: email,
subject: "Connexion à OwlCub Academy",
html: `
<div style="font-family: -apple-system, sans-serif; max-width: 480px; margin: 0 auto; padding: 32px 24px; background: #0f1117; color: #f1f5f9;">
<div style="background: #1d4ed8; padding: 16px 24px; border-radius: 8px 8px 0 0; margin-bottom: 0;">
<h2 style="color: #fff; font-size: 20px; margin: 0;">OwlCub Academy</h2>
</div>
<div style="background: #1a1f2e; padding: 32px 24px; border-radius: 0 0 8px 8px;">
<p style="color: #94a3b8; margin-bottom: 24px; font-size: 16px;">Cliquez sur le lien ci-dessous pour vous connecter :</p>
<a href="${url}" style="display: inline-block; background: #1d4ed8; color: #fff; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: 600; font-size: 16px;">Se connecter</a>
<p style="color: #475569; font-size: 12px; margin-top: 24px;">Ce lien expire dans 24 heures. Si vous n'avez pas demandé ce lien, ignorez cet email.</p>
</div>
</div>
`,
});
},
}),
],
session: { strategy: "database" },
pages: {
signIn: "/auth/login",
verifyRequest: "/auth/verify",
newUser: "/dashboard",
},
callbacks: {
session({ session, user }) {
if (session.user) {
(session.user as any).id = user.id;
(session.user as any).role = (user as any).role;
(session.user as any).locale = (user as any).locale;
}
return session;
},
},
});