diagnosing problem with session storage
This commit is contained in:
@@ -3,6 +3,8 @@ import { User } from "../models/user";
|
||||
import createError from "http-errors";
|
||||
import bcrypt from "bcrypt";
|
||||
import now from "../util/now";
|
||||
import ControllerResponse from "../util/ControllerResponse";
|
||||
import { StatusCode } from "../util/types";
|
||||
|
||||
const UserInstance = new User();
|
||||
|
||||
@@ -46,13 +48,13 @@ export default class AuthService {
|
||||
const { email, password } = data;
|
||||
|
||||
try {
|
||||
const user = await UserInstance.getOneByEmail(email);
|
||||
if (!user) return { ok: false, user: null }
|
||||
const match = await bcrypt.compare(password, user.password);
|
||||
return {
|
||||
ok: match,
|
||||
user: match ? user : null
|
||||
}
|
||||
const response: IUser = await UserInstance.getOneByEmail(email);
|
||||
const match = await bcrypt.compare(password, response.password!);
|
||||
const user = match ? response : null;
|
||||
const code = match ? StatusCode.OK : StatusCode.Forbidden;
|
||||
|
||||
return new ControllerResponse(code, user, match);
|
||||
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { NextFunction, Request, Response } from "express"
|
||||
import e, { NextFunction, Request, Response } from "express"
|
||||
import ControllerResponse from "../util/ControllerResponse";
|
||||
import { StatusCode } from "../util/types";
|
||||
|
||||
export function restrictAccess(req: Request, res: Response, next: NextFunction) {
|
||||
if (req.isAuthenticated()) {
|
||||
if (req.session.user == undefined) {
|
||||
console.log("restricted")
|
||||
res.send(undefined);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user