add sign in

This commit is contained in:
2025-04-04 12:23:24 +02:00
parent 27f7d3dd2c
commit 5ca9104e7b
4 changed files with 53 additions and 37 deletions

View File

@@ -20,15 +20,11 @@ declare module 'next-auth' {
interface Session extends DefaultSession {
user: {
id: string
discord_id: string
// ...other properties
// role: UserRole;
} & DefaultSession['user']
}
// interface User {
// // ...other properties
// // role: UserRole;
// }
}
/**
@@ -38,7 +34,27 @@ declare module 'next-auth' {
*/
export const authConfig = {
providers: [
DiscordProvider,
DiscordProvider({
profile(profile) {
if (profile.avatar === null) {
const defaultAvatarNumber =
profile.discriminator === '0'
? Number(BigInt(profile.id) >> BigInt(22)) % 6
: Number.parseInt(profile.discriminator) % 5
profile.image_url = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`
} else {
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png'
profile.image_url = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`
}
return {
id: profile.id,
name: profile.global_name ?? profile.username,
email: profile.email,
image: profile.image_url,
discord_id: profile.id.toString(),
}
},
}),
/**
* ...add more providers here.
*
@@ -61,6 +77,7 @@ export const authConfig = {
user: {
...session.user,
id: user.id,
discord_id: session.user.discord_id,
},
}),
},

View File

@@ -62,6 +62,8 @@ export const users = pgTable('user', (d) => ({
})
.default(sql`CURRENT_TIMESTAMP`),
image: d.varchar({ length: 255 }),
discord_id: d.varchar({ length: 255 }),
role: d.varchar({ length: 255 }).notNull().default('user'),
}))
export const usersRelations = relations(users, ({ many }) => ({