-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.ts
55 lines (49 loc) · 1.37 KB
/
auth.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
// @utils
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
// @actions
import { storeProfile } from "@/lib/actions";
// @types
import { GitHubProfile } from "next-auth/providers/github";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [GitHub],
callbacks: {
async jwt({ token, profile }: any) {
const githubProfile = profile as GitHubProfile;
if (profile) {
token.login = githubProfile.login;
await storeProfile({
name: githubProfile.name,
bio: githubProfile.bio,
avatar: githubProfile.avatar_url,
email: githubProfile.email,
username: githubProfile.login,
portfolio: githubProfile.blog,
location: githubProfile.location,
x: githubProfile.twitter_username,
following: githubProfile.following,
followers: githubProfile.followers,
createdAt: githubProfile.created_at,
updatedAt: githubProfile.updated_at,
repositories: githubProfile.public_repos,
});
}
return token;
},
async session({ session, token }) {
return {
...session,
user: {
...session.user,
login: token.login,
},
};
},
authorized: async ({ auth }) => {
return !!auth;
},
},
pages: {
signIn: "/",
},
});