-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
40 lines (38 loc) · 953 Bytes
/
auth.ts
File metadata and controls
40 lines (38 loc) · 953 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
32
33
34
35
36
37
38
39
40
import NextAuth from "next-auth";
import SpotifyProvider from "next-auth/providers/spotify";
const SCOPES = [
"user-top-read",
"playlist-modify-private",
"playlist-modify-public",
"user-read-private user-read-email",
];
export const {
handlers: { GET, POST },
auth,
} = NextAuth({
providers: [
SpotifyProvider({
clientId: process.env.SPOTIFY_CLIENT_ID,
clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
authorization: `https://accounts.spotify.com/authorize?scope=${SCOPES.join(
" "
)}`,
}),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async jwt({ token, account, user }) {
if (account) {
token.id = user.id;
token.expiresAt = account.expires_at;
token.accessToken = account.access_token;
}
return token;
},
async session({ session, token }) {
//@ts-ignore
session.user = token;
return session;
},
},
});