-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
59 lines (54 loc) · 1.24 KB
/
Copy pathauth.ts
File metadata and controls
59 lines (54 loc) · 1.24 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
import type { NextAuthConfig } from "next-auth";
declare module "next-auth" {
interface Session {
accessToken?: string;
user: {
id?: string;
name?: string | null;
email?: string | null;
image?: string | null;
username?: string;
};
}
}
declare module "@auth/core/jwt" {
interface JWT {
accessToken?: string;
username?: string;
}
}
export const authConfig: NextAuthConfig = {
providers: [
GitHub({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
}),
],
callbacks: {
async jwt({ token, account, profile }) {
if (account) {
token.accessToken = account.access_token;
}
if (profile) {
token.username = (profile as { login?: string }).login;
}
return token;
},
async session({ session, token }) {
session.accessToken = token.accessToken;
if (session.user) {
session.user.username = token.username;
}
return session;
},
},
pages: {
signIn: "/login",
},
session: {
strategy: "jwt",
},
};
export const { handlers, auth, signIn, signOut } = NextAuth(authConfig);