mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add error handling for oauthVerify
This commit is contained in:
1 parent
8d0ec00536
commit
8430ce4428
1 file changed
+24
-20
@@ -2,27 +2,31 @@ import { User } from '@linux-odyssey/models'
|
||||
|
||||
export default async function oauthVerify(provider, profile, query, cb) {
|
||||
process.nextTick(async () => {
|
||||
const email = profile.emails[0]?.value
|
||||
if (!email) {
|
||||
return cb(new Error('No email found'))
|
||||
}
|
||||
|
||||
const socialLogin = {
|
||||
provider,
|
||||
id: profile.id,
|
||||
displayName: profile.displayName,
|
||||
}
|
||||
let user = await User.findOne(query)
|
||||
if (!user) {
|
||||
user = await User.findOne({ email })
|
||||
if (!user) {
|
||||
const newUser = { email, socialLogin }
|
||||
return cb(null, { newUser })
|
||||
try {
|
||||
const email = profile.emails[0]?.value
|
||||
if (!email) {
|
||||
return cb(new Error('No email found'))
|
||||
}
|
||||
user.socialLogins.set(provider, socialLogin)
|
||||
await user.save()
|
||||
}
|
||||
|
||||
return cb(null, user)
|
||||
const socialLogin = {
|
||||
provider,
|
||||
id: profile.id,
|
||||
displayName: profile.displayName,
|
||||
}
|
||||
let user = await User.findOne(query)
|
||||
if (!user) {
|
||||
user = await User.findOne({ email })
|
||||
if (!user) {
|
||||
const newUser = { email, socialLogin }
|
||||
return cb(null, { newUser })
|
||||
}
|
||||
user.socialLogins.set(provider, socialLogin)
|
||||
await user.save()
|
||||
}
|
||||
|
||||
return cb(null, user)
|
||||
} catch (err) {
|
||||
return cb(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user