1
Fork 0
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:
dicedtomato 2020-09-17 08:59:58 -07:00 committed by GitHub
parent 10b51a88cb
commit 0ce137a467
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
}
}