mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
feat: enabled session based authentication for web
This commit is contained in:
@@ -2,6 +2,10 @@ import jwt from 'jsonwebtoken'
|
||||
import { verifyTokenInDB } from '../utils'
|
||||
|
||||
export const authenticateAccessToken = (req: any, res: any, next: any) => {
|
||||
if (req.session?.loggedIn) {
|
||||
req.user = req.session.user
|
||||
return next()
|
||||
}
|
||||
authenticateToken(
|
||||
req,
|
||||
res,
|
||||
@@ -43,9 +47,7 @@ const authenticateToken = (
|
||||
}
|
||||
|
||||
const authHeader = req.headers['authorization']
|
||||
const token =
|
||||
authHeader?.split(' ')[1] ??
|
||||
(tokenType === 'accessToken' ? req.cookies.accessToken : '')
|
||||
const token = authHeader?.split(' ')[1]
|
||||
if (!token) return res.sendStatus(401)
|
||||
|
||||
jwt.verify(token, key, async (err: any, data: any) => {
|
||||
|
||||
Reference in New Issue
Block a user