1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-08 15:00:05 +00:00

fix(web): ability to use get/patch User API in desktop mode.

This commit is contained in:
Saad Jutt
2022-05-27 17:01:14 +05:00
parent b066734398
commit 2c259fe1de
6 changed files with 79 additions and 14 deletions

View File

@@ -1,15 +1,22 @@
import { RequestHandler, Request, Response, NextFunction } from 'express'
import jwt from 'jsonwebtoken'
import { csrfProtection } from '../app'
import { fetchLatestAutoExec, verifyTokenInDB } from '../utils'
import { fetchLatestAutoExec, ModeType, verifyTokenInDB } from '../utils'
import { desktopUser } from './desktop'
export const authenticateAccessToken: RequestHandler = async (
req,
res,
next
) => {
const { MODE } = process.env
if (MODE === ModeType.Server) {
req.user = desktopUser
return next()
}
// if request is coming from web and has valid session
// we can validate the request and check for CSRF Token
// it can be validated.
if (req.session?.loggedIn) {
if (req.session.user) {
const user = await fetchLatestAutoExec(req.session.user)