-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathauth.ts
More file actions
44 lines (43 loc) · 1.28 KB
/
auth.ts
File metadata and controls
44 lines (43 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import NextAuth from "next-auth";
import { PrismaAdapter } from "@auth/prisma-adapter";
import Resend from "next-auth/providers/resend";
import GoogleProvider from "next-auth/providers/google";
import GitHubProvider from "next-auth/providers/github";
import { db as prisma } from "@/lib/db";
import { env } from "@/lib/env";
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
Resend({
from: env.EMAIL_FROM,
}),
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true,
}),
GitHubProvider({
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true,
}),
],
pages: {
signIn: "/auth/signin",
verifyRequest: "/auth/verify-request",
error: "/auth/error",
},
callbacks: {
async signIn() {
return true;
},
async redirect({ url, baseUrl }) {
if (url.includes("/invite/accept")) {
return url.startsWith("/") ? `${baseUrl}${url}` : url;
}
if (url.startsWith("/")) return `${baseUrl}/dashboard`;
else if (new URL(url).origin === baseUrl) return url;
return `${baseUrl}/dashboard`;
},
},
});