mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor utils
This commit is contained in:
1 parent
9509bbc355
commit
d6c95cea4a
13 files changed
+126
-31
No files matched your search
@@ -1,9 +1,22 @@
|
||||
import { User } from '@linux-odyssey/models'
|
||||
import type { Profile } from 'passport'
|
||||
import type { VerifyCallback } from 'passport-oauth2'
|
||||
|
||||
export default async function oauthVerify(provider, profile, query, cb) {
|
||||
export type SocialLogin = {
|
||||
provider: string
|
||||
id: string
|
||||
displayName: string
|
||||
}
|
||||
|
||||
export default async function oauthVerify(
|
||||
provider: string,
|
||||
profile: Profile,
|
||||
query: Record<string, any>,
|
||||
cb: VerifyCallback
|
||||
) {
|
||||
process.nextTick(async () => {
|
||||
try {
|
||||
const email = profile.emails[0]?.value
|
||||
const email = profile.emails ? profile.emails[0]?.value : undefined
|
||||
if (!email) {
|
||||
return cb(new Error('No email found'))
|
||||
}
|
||||
@@ -26,7 +39,9 @@ export default async function oauthVerify(provider, profile, query, cb) {
|
||||
|
||||
return cb(null, user)
|
||||
} catch (err) {
|
||||
return cb(err)
|
||||
return cb(
|
||||
err instanceof Error ? err : new Error('An unknown error occurred')
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user