refactor: Create a better API scheme
This commit is contained in:
23
backend/src/security/token.ts
Normal file
23
backend/src/security/token.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
import { isAuthenticated } from "../security/auth";
|
||||
|
||||
export async function authRoute(req: Request, res: Response, next: () => void) {
|
||||
const token = req.get("Token");
|
||||
if (token) {
|
||||
// Check if were authenticated
|
||||
const auth = await isAuthenticated(token);
|
||||
if (auth)
|
||||
next();
|
||||
else
|
||||
res.send({
|
||||
error: "401",
|
||||
data: {},
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
error: "401",
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user