-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.config.mjs
More file actions
52 lines (49 loc) · 1.66 KB
/
Copy pathauth.config.mjs
File metadata and controls
52 lines (49 loc) · 1.66 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
import TwitchProvider from '@auth/core/providers/twitch';
import { db, eq, User } from "astro:db";
import { defineConfig } from 'auth-astro';
import { getSubscriptionTier, TWITCH_SCOPES } from '@/lib/twitch';
import { createOrUpdateUser } from "@/utils/users";
export default defineConfig({
providers: [
TwitchProvider({
clientId: import.meta.env.TWITCH_CLIENT_ID,
clientSecret: import.meta.env.TWITCH_CLIENT_SECRET,
authorization: {
params: {
scope: TWITCH_SCOPES.join(' '),
force_verify: true,
}
}
})
],
callbacks: {
jwt: async ({ token, user, account, profile }) => {
if (user) {
token.user = profile
console.log({ user, account, profile });
try {
const tier = await getSubscriptionTier(profile.sub, account.access_token);
await createOrUpdateUser({
id: profile.sub,
username: user.name.toLowerCase(),
displayName: profile.preferred_username,
avatar: profile.picture,
twitchTier: tier,
})
} catch (error) {
console.error(error);
}
}
return Promise.resolve(token);
},
session: ({ session, token }) => {
return {
...session,
user: {
...session.user,
id: token.user.sub,
}
}
},
}
});