-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
31 lines (29 loc) · 993 Bytes
/
Copy pathauth.ts
File metadata and controls
31 lines (29 loc) · 993 Bytes
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
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
import { buildClientSession, persistGitHubIdentity } from "@/lib/auth/callbacks";
import { assertAuthEnv } from "@/lib/env";
assertAuthEnv();
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: {
// Both live in lib/auth/callbacks.ts so the boundary they draw -- access
// token in the JWT, never in the session -- is unit-testable.
async jwt({ token, account, profile }) {
return persistGitHubIdentity({ token, account, profile });
},
async session({ session, token }) {
return buildClientSession({ session, token });
},
},
});