mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add /users/me endpoint
This commit is contained in:
1 parent
ae221a696c
commit
a7422853fa
8 files changed
+112
-19
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { Router } from 'express'
|
||||
import passport from 'passport'
|
||||
|
||||
import enabledMethods from '../../auth/passport.js'
|
||||
|
||||
import {
|
||||
register,
|
||||
checkSession,
|
||||
logout,
|
||||
socialLogin,
|
||||
registerFromSession,
|
||||
} from '../controllers/authController.js'
|
||||
import {
|
||||
checkUsernameValidators,
|
||||
loginValidators,
|
||||
registerFromSessionValidators,
|
||||
registerValidators,
|
||||
} from '../validators/authValidator.js'
|
||||
import { authenticateRateLimit } from '../../middleware/rateLimiter.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post(
|
||||
'/login',
|
||||
authenticateRateLimit,
|
||||
loginValidators,
|
||||
passport.authenticate('local', { failureMessage: true }),
|
||||
(req, res) => {
|
||||
res.json({ message: 'success' })
|
||||
}
|
||||
)
|
||||
|
||||
router.post('/register', authenticateRateLimit, registerValidators, register)
|
||||
|
||||
router.post('/logout', authenticateRateLimit, logout)
|
||||
|
||||
router.get('/check-username', checkUsernameValidators, (req, res) =>
|
||||
res.json({ available: true })
|
||||
)
|
||||
router.get('/check-session', checkSession)
|
||||
|
||||
router.get('/available-methods', (req, res) => {
|
||||
res.json(enabledMethods)
|
||||
})
|
||||
|
||||
if (enabledMethods.google) {
|
||||
router.get('/google', passport.authenticate('google'))
|
||||
router.get(
|
||||
'/google/callback',
|
||||
authenticateRateLimit,
|
||||
passport.authenticate('google'),
|
||||
socialLogin
|
||||
)
|
||||
}
|
||||
|
||||
if (enabledMethods.github) {
|
||||
router.get('/github', passport.authenticate('github'))
|
||||
router.get(
|
||||
'/github/callback',
|
||||
authenticateRateLimit,
|
||||
passport.authenticate('github'),
|
||||
socialLogin
|
||||
)
|
||||
}
|
||||
|
||||
router.post(
|
||||
'/register-from-session',
|
||||
authenticateRateLimit,
|
||||
registerFromSessionValidators,
|
||||
registerFromSession
|
||||
)
|
||||
|
||||
export default router
|
||||
Reference in new issue
Block a user