roles-bot/apps/website/auth.config.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

import Discord from "@auth/core/providers/discord";
import { defineConfig } from "auth-astro";
2024-08-03 10:46:56 +02:00
import type { User } from "~/env";
export default defineConfig({
2024-08-02 23:43:42 +02:00
providers: [
Discord({
clientId: import.meta.env.DISCORD_CLIENT_ID,
clientSecret: import.meta.env.DISCORD_CLIENT_SECRET,
authorization:
"https://discord.com/api/oauth2/authorize?scope=guilds+identify+email",
}),
],
callbacks: {
async jwt({ token, account, profile }) {
if (account && profile) {
token.accessToken = account.access_token;
token.id = profile.id;
2024-08-03 10:46:56 +02:00
token.name = profile.username as string;
token.global_name = profile.global_name;
2024-08-02 23:43:42 +02:00
}
return token;
},
async session({ session, token }) {
if (session.user) {
session.user.id = token.id as string;
2024-08-03 10:46:56 +02:00
(session.user as unknown as User).global_name =
token.global_name as string;
2024-08-02 23:43:42 +02:00
2024-08-03 14:42:34 +02:00
(session.user as unknown as User).discordAccessToken =
token.accessToken as string;
2024-08-02 23:43:42 +02:00
}
return session;
},
},
pages: {
signIn: "/auth/login",
signOut: "/auth/logout",
},
});