-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
55 lines (52 loc) · 1.31 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
import NextAuth, { NextAuthConfig, Profile } from "next-auth";
import type { OAuth2Config } from "next-auth/providers";
import { IDProfile } from "./types";
export const PurdueHackersIDProvider: OAuth2Config<IDProfile> = {
id: 'purduehackers-id',
name: 'Purdue Hackers ID',
type: 'oauth',
authorization: {
url: 'https://id.purduehackers.com/api/authorize',
params: {
scope: 'user:read user',
response_mode: 'form_post'
}
},
checks: [],
token: {
url: 'https://id.purduehackers.com/api/token',
},
client: {
token_endpoint_auth_method: 'client_secret_post',
},
issuer: 'https://id.purduehackers.com/api',
userinfo: {
url: 'https://id.purduehackers.com/api/user'
},
clientId: 'auth-test',
clientSecret: '0',
}
export const authConfig = {
providers: [
PurdueHackersIDProvider
],
secret: process.env.AUTH_SECRET,
callbacks: {
async jwt({ token, profile }) {
if (profile) {
token.profile = profile;
}
return token;
},
async session({ session, token }) {
if (token.profile) {
session.user = {
...session.user,
...token.profile
}
}
return { ...session };
},
},
} satisfies NextAuthConfig
export const { handlers: { GET, POST }, signIn, signOut, auth } = NextAuth(authConfig);