-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthOptions.ts
83 lines (71 loc) · 2.26 KB
/
authOptions.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { NextAuthOptions } from "next-auth";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
import { prisma } from "./lib/prisma";
export const authOptions: NextAuthOptions = {
secret: process.env.NEXT_AUTH_SECRET,
// Use Prisma as the adapter for storing user accounts
adapter: PrismaAdapter(prisma),
// Configure GitHub as the authentication provider
providers: [
GithubProvider({
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
// Custom profile data mapping
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name || profile.login,
email: profile.email,
image: profile.avatar_url,
};
},
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
}),
],
session: {
strategy: "jwt",
},
// Callbacks to customize session and token
callbacks: {
// Customize the session object
async session({ session, token }) {
if (token.sub) {
session.user.id = token.sub;
}
if (token.provider === "github" && token.accessToken) {
session.user.accessToken = token.accessToken;
session.user.provider = "github";
}
return session;
},
// Customize the JWT token
async jwt({ token, account, profile }) {
if (account?.provider === "github") {
token.accessToken = account.access_token;
token.provider = "github";
}
return token;
},
// Customize the sign-in process to handle different scopes
async signIn({ account }) {
// You can add additional validation or logging here
if (account?.provider === "github") {
// Log the scopes requested during sign-in
console.log("GitHub Sign-In Scopes:", account.scope);
return true;
}
return true;
},
},
// Customize authentication pages
pages: {
signIn: "/auth/sign-in", // Custom sign-in page
error: "/auth/error", // Uncomment if you want a custom error page
},
debug: process.env.NODE_ENV === "development",
};