2024-07-16 19:29:20 +02:00
|
|
|
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";
|
2024-07-16 19:29:20 +02:00
|
|
|
|
|
|
|
export default defineConfig({
|
2024-08-03 16:49:53 +02:00
|
|
|
secret: import.meta.env.AUTH_SECRET,
|
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",
|
|
|
|
},
|
2024-07-16 19:29:20 +02:00
|
|
|
});
|