defined access check middleware, corrected login flow
This commit is contained in:
@@ -21,7 +21,7 @@ export default class AuthService {
|
||||
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
if (err) throw err;
|
||||
bcrypt.hash(password, salt, async (err, hash) => {
|
||||
bcrypt.hash(password!, salt, async (err, hash) => {
|
||||
if (err) throw err;
|
||||
const newData = {
|
||||
...data,
|
||||
|
||||
14
server/auth/middlewares.ts
Normal file
14
server/auth/middlewares.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { NextFunction, Request, Response } from "express"
|
||||
|
||||
export function restrictAccess(req: Request, res: Response, next: NextFunction) {
|
||||
if (!req.isAuthenticated()) {
|
||||
res.status(403).send({ message: "Access forbidden" });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
export function checkAccess(req: Request, res: Response, next: NextFunction) {
|
||||
console.log(req.isAuthenticated());
|
||||
next();
|
||||
}
|
||||
Reference in New Issue
Block a user