added frontend + securing beta server invites
This commit is contained in:
30
web/auth.ts
Normal file
30
web/auth.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import NextAuth from "next-auth"
|
||||
import Discord from "next-auth/providers/discord"
|
||||
|
||||
export const { handlers, signIn, signOut, auth } = NextAuth({
|
||||
providers: [
|
||||
Discord({
|
||||
authorization: "https://discord.com/api/oauth2/authorize?scope=identify+email+guilds",
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
async jwt({ token, account, profile }) {
|
||||
if (account) {
|
||||
token.accessToken = account.access_token
|
||||
token.discordId = account.providerAccountId
|
||||
}
|
||||
if (profile) {
|
||||
token.discordId = profile.id
|
||||
}
|
||||
return token
|
||||
},
|
||||
async session({ session, token }) {
|
||||
// @ts-expect-error - accessToken is not strictly typed in session yet
|
||||
session.accessToken = token.accessToken
|
||||
if (session.user && token.discordId) {
|
||||
session.user.id = token.discordId as string
|
||||
}
|
||||
return session
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user