-
Notifications
You must be signed in to change notification settings - Fork 581
Expand file tree
/
Copy pathauth.ts
More file actions
27 lines (26 loc) · 810 Bytes
/
Copy pathauth.ts
File metadata and controls
27 lines (26 loc) · 810 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
import NextAuth from 'next-auth';
import GitHub from 'next-auth/providers/github';
import { encryptToken } from '@/lib/crypto';
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
GitHub({
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
authorization: { params: { scope: 'read:user public_repo' } },
}),
],
session: { strategy: 'jwt' },
callbacks: {
async jwt({ token, account }) {
if (account?.access_token) {
token.ghToken = encryptToken(account.access_token);
}
return token;
},
async session({ session, token }) {
session.hasGitHubToken = Boolean(token.ghToken);
session.ghToken = token.ghToken as string | undefined;
return session;
},
},
});