mirror of
https://github.com/ershisan99/www.git
synced 2026-01-25 21:02:08 +00:00
add sign in
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -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 }) => ({
|
||||
|
||||
Reference in New Issue
Block a user