refactor: Create a better API scheme

This commit is contained in:
Alexander Polynomdivision
2018-09-23 22:17:35 +02:00
parent a7dc7464a1
commit 2c4011f631
6 changed files with 226 additions and 80 deletions

View 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: {},
});
}
};