mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
Update cookiesForAPI.ts
This commit is contained in:
parent
10b51a88cb
commit
0ce137a467
1 changed files with 8 additions and 2 deletions
|
@ -1,9 +1,15 @@
|
|||
import { Request, Response } from "express";
|
||||
import config from '../../config.json';
|
||||
import { BAD_REQUEST, INTERNAL_SERVER_ERROR, FORBIDDEN } from 'http-status-codes'
|
||||
import { getConnection } from 'typeorm';
|
||||
import { User } from "../entities/User";
|
||||
|
||||
if (!findFile('config.json', process.cwd())) {
|
||||
Logger.get('FS').error(`No config.json exists in ${__dirname}, exiting...`)
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const config = JSON.parse(readFileSync(findFile('config.json', process.cwd()), 'utf8'))
|
||||
|
||||
export async function cookiesForAPI(req: Request, res: Response, next: any) {
|
||||
if (req.cookies.typex_user) {
|
||||
if (typeof req.cookies.typex_user !== 'string') return res.status(BAD_REQUEST).send({ code: BAD_REQUEST, message: "Please clear browser cookies." })
|
||||
|
@ -17,4 +23,4 @@ export async function cookiesForAPI(req: Request, res: Response, next: any) {
|
|||
if (!req.session.user) return res.status(INTERNAL_SERVER_ERROR).send({ code: INTERNAL_SERVER_ERROR, message: "The user that is logged in does not exist" })
|
||||
} else return res.status(FORBIDDEN).send({ code: FORBIDDEN, message: "Unauthorized" })
|
||||
return next();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue