mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +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) {
|
export default async function oauthVerify(provider, profile, query, cb) {
|
||||||
process.nextTick(async () => {
|
process.nextTick(async () => {
|
||||||
const email = profile.emails[0]?.value
|
try {
|
||||||
if (!email) {
|
const email = profile.emails[0]?.value
|
||||||
return cb(new Error('No email found'))
|
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 })
|
|
||||||
}
|
}
|
||||||
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