-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
38 lines (37 loc) · 1.06 KB
/
auth.ts
File metadata and controls
38 lines (37 loc) · 1.06 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
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
GitHub({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
authorization: {
params: {
// Request additional scopes for repository access
scope: "read:user user:email repo workflow",
},
},
}),
],
callbacks: {
async jwt({ token, account, profile }) {
// Persist the OAuth access token and user ID to the JWT
if (account) {
token.accessToken = account.access_token;
}
if (profile) {
// GitHub profile includes the user's ID
token.userId = String(profile.id);
}
return token;
},
async session({ session, token }) {
// Send the access token and user ID to the client
session.accessToken = token.accessToken as string;
if (session.user) {
session.user.id = token.userId as string;
}
return session;
},
},
});