forked from EddieHubCommunity/BioDrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
[...nextauth].js
54 lines (50 loc) · 1.43 KB
/
[...nextauth].js
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
import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";
import DbAdapter from "./db-adapter";
import connectMongo from "@config/mongo";
export const authOptions = {
adapter: DbAdapter(connectMongo),
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
username: profile.login,
email: profile.email,
image: profile.avatar_url,
};
},
}),
],
session: {
strategy: "jwt",
},
callbacks: {
async redirect({ url, baseUrl }) {
return `${baseUrl}/account/statistics`;
},
async jwt({ token, account, profile }) {
// Persist the OAuth access_token and or the user id to the token right after signin
if (account) {
token.accessToken = account.access_token;
token.id = profile.id;
token.username = profile.login;
}
return token;
},
async session({ session, token, user, profile }) {
// Send properties to the client, like an access_token and user id from a provider.
session.accessToken = token.accessToken;
session.user.id = token.id;
session.username = token.username;
return session;
},
},
pages: {
signIn: "/auth/signin",
}
};
export default NextAuth(authOptions);