我正尝试在我的网站上使用discord api,但是在车把文件中使用acyno函数的最干净的方法是什么? 我要导出的代码:
passport.use(new DiscordStrategy({
clientID: '',
clientSecret: '',
callbackURL: 'http://localhost:3000/app/discord/callback',
scope: scopes
}, async function(accessToken, refreshToken, profile, cb) {
try {
// First check if a user with the same email exists
let user = await User.findOne({ email: profile.email })
// Check if a user with the same discord ID exists
if (!user) user = await User.findOne({ discordId: profile.id })
console.log(`Avatar : ${profile.avatar} \nUsername: ${profile.username}\nID: ${profile.id}`)
if (user) {
// A user was found
if (user.discordId !== profile.id) {
// Store the discord ID in the database
user.discordId = profile.id
await user.save()
}
return cb(null, user)
} else {
// No user found, create one
const newUser = new User({
name: profile.username,
discordId: profile.id
})
// No need for a password
await newUser.save()
return cb(null, newUser)
}
} catch (err) {
console.log(err)
return cb(err)
}
}));
我需要将其导出以使用profile
对象中的数据