2023-07-11 23:17:58 +02:00
|
|
|
const { Strategy: DiscordStrategy } = require('passport-discord');
|
2024-06-06 19:23:11 +02:00
|
|
|
const socialLogin = require('./socialLogin');
|
2023-07-11 23:17:58 +02:00
|
|
|
|
2025-01-31 15:49:09 +01:00
|
|
|
const getProfileDetails = ({ profile }) => {
|
2024-06-06 19:23:11 +02:00
|
|
|
let avatarUrl;
|
|
|
|
if (profile.avatar) {
|
|
|
|
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png';
|
|
|
|
avatarUrl = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
|
|
|
|
} else {
|
|
|
|
const defaultAvatarNum = Number(profile.discriminator) % 5;
|
|
|
|
avatarUrl = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNum}.png`;
|
2023-08-18 16:11:00 +02:00
|
|
|
}
|
2024-06-06 19:23:11 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
email: profile.email,
|
|
|
|
id: profile.id,
|
|
|
|
avatarUrl,
|
|
|
|
username: profile.username,
|
|
|
|
name: profile.global_name,
|
2024-06-07 21:06:47 +02:00
|
|
|
emailVerified: true,
|
2024-06-06 19:23:11 +02:00
|
|
|
};
|
2023-08-18 16:11:00 +02:00
|
|
|
};
|
|
|
|
|
2024-06-06 19:23:11 +02:00
|
|
|
const discordLogin = socialLogin('discord', getProfileDetails);
|
|
|
|
|
2023-08-18 16:11:00 +02:00
|
|
|
module.exports = () =>
|
2023-07-22 07:29:17 -07:00
|
|
|
new DiscordStrategy(
|
|
|
|
{
|
|
|
|
clientID: process.env.DISCORD_CLIENT_ID,
|
|
|
|
clientSecret: process.env.DISCORD_CLIENT_SECRET,
|
2023-11-25 16:34:51 -05:00
|
|
|
callbackURL: `${process.env.DOMAIN_SERVER}${process.env.DISCORD_CALLBACK_URL}`,
|
2023-08-18 16:11:00 +02:00
|
|
|
scope: ['identify', 'email'],
|
|
|
|
authorizationURL: 'https://discord.com/api/oauth2/authorize?prompt=none',
|
2023-07-22 07:29:17 -07:00
|
|
|
},
|
2023-08-18 16:11:00 +02:00
|
|
|
discordLogin,
|
2023-07-22 07:29:17 -07:00
|
|
|
);
|