mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
import passport from 'passport'
|
|
import { UserProfile } from '@linux-odyssey/models'
|
|
import passwordStrategy from './passwordStrategy.js'
|
|
import jwtStrategy from './jwtStrategy.js'
|
|
import googleStrategy from './googleStrategy.js'
|
|
import githubStrategy from './githubStrategy.js'
|
|
|
|
passport.use(passwordStrategy)
|
|
passport.use(jwtStrategy)
|
|
|
|
const enabledMethods = {
|
|
local: true,
|
|
google: googleStrategy !== null,
|
|
github: githubStrategy !== null,
|
|
}
|
|
|
|
console.log('Enabled login methods', enabledMethods)
|
|
|
|
if (enabledMethods.google) {
|
|
passport.use(googleStrategy)
|
|
}
|
|
|
|
if (enabledMethods.github) {
|
|
passport.use(githubStrategy)
|
|
}
|
|
|
|
passport.serializeUser((user, done) => {
|
|
process.nextTick(async () => {
|
|
if (!(await UserProfile.exists({ user: user._id }))) {
|
|
UserProfile.create({ user: user._id })
|
|
}
|
|
done(null, {
|
|
_id: user._id,
|
|
username: user.username,
|
|
email: user.email,
|
|
})
|
|
})
|
|
})
|
|
|
|
passport.deserializeUser((user, done) => {
|
|
process.nextTick(() => {
|
|
done(null, user)
|
|
})
|
|
})
|
|
|
|
export default enabledMethods
|