adding in old api

This commit is contained in:
talksik
2022-06-02 10:48:00 -05:00
parent 33ea29457a
commit 5f644c94ba
15 changed files with 1303 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { NextFunction, Request, Response } from "express";
import { loadConfig } from "../config";
const jwt = require("jsonwebtoken");
const config = loadConfig();
// used by specific routes that need to authentication
export const authCheck = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { authorization } = req.headers;
if (!authorization) {
throw Error("No provided header");
}
// verify jwt token with our api secret
var decoded: JwtClaims = jwt.verify(authorization, config.JWT_TOKEN_SECRET);
res.locals.userInfo = decoded;
next();
} catch (error) {
res.status(401).send("unauthorized");
}
};
export interface JwtClaims {
userId: string;
googleUserId: string;
picture: string;
email: string;
name: string;
}