diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-03-23 16:24:32 -0400 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2025-03-23 16:24:32 -0400 |
| commit | a19b6ed4ef829697fd0be153af5e27c99f267787 (patch) | |
| tree | e0fbd044f2cdfb937d43ff26e6958aadf91ebde7 /web/src/lib/auth.js | |
| parent | d7c46a9eae28046bb26da182abc298dc18ed5a10 (diff) | |
| download | AleeBot-a19b6ed4ef829697fd0be153af5e27c99f267787.tar.gz AleeBot-a19b6ed4ef829697fd0be153af5e27c99f267787.tar.bz2 AleeBot-a19b6ed4ef829697fd0be153af5e27c99f267787.zip | |
Fundementials of the new dashboard
Diffstat (limited to 'web/src/lib/auth.js')
| -rw-r--r-- | web/src/lib/auth.js | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/web/src/lib/auth.js b/web/src/lib/auth.js index bc482b1..3f78f94 100644 --- a/web/src/lib/auth.js +++ b/web/src/lib/auth.js @@ -2,5 +2,38 @@ import NextAuth from "next-auth" import Discord from "next-auth/providers/discord" export const { handlers, signIn, signOut, auth } = NextAuth({ - providers: [Discord], + providers: [Discord({ + authorization: { + profile(profile) { + return { + id: profile.id, + name: profile.username, + image: profile.image_url + } + }, + url: "https://discord.com/api/oauth2/authorize", + params: { scope: "identify guilds" }, + } + })], + callbacks: { + async jwt({ token, account }) { + // Persist the OAuth access_token to the token right after sign in + if (account) { + token.accessToken = account.access_token; + } + return token; + }, + async session({ session, token }) { + if (token.accessToken) { + session.user = await fetch('https://discord.com/api/users/@me', { + headers: { + authorization: `Bearer ${token.accessToken}` + } + }).then((r) => r.json()); + session.accessToken = token.accessToken; + } + + return session; + } + } }) |
