adding axios and call to backend working with the auth check middleware
This commit is contained in:
@@ -12,17 +12,21 @@ export const authCheck = async (
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
console.log(req.headers);
|
||||
const { authorization } = req.headers;
|
||||
console.log(authorization);
|
||||
|
||||
// todo get idToken from frontend
|
||||
const ticket = await client.verifyIdToken({
|
||||
idToken: "",
|
||||
audience:
|
||||
"423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com", // Specify the CLIENT_ID of the app that accesses the backend
|
||||
});
|
||||
const userid = ticket.getPayload()?.sub;
|
||||
try {
|
||||
const ticket = await client.verifyIdToken({
|
||||
idToken: authorization ?? "",
|
||||
audience:
|
||||
"423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com", // Specify the CLIENT_ID of the app that accesses the backend
|
||||
});
|
||||
const userid = ticket.getPayload()?.sub;
|
||||
|
||||
console.log(userid);
|
||||
console.log(userid);
|
||||
|
||||
next();
|
||||
next();
|
||||
} catch (error) {
|
||||
res.status(401).send(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ignore": ["**/*.test.ts", "**/*.spec.ts", "node_modules"],
|
||||
"watch": ["src"],
|
||||
"watch": ["./"],
|
||||
"exec": "npm start",
|
||||
"ext": "ts"
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import express, { Application, Request, Response } from "express";
|
||||
|
||||
import { authCheck } from "../middleware/auth";
|
||||
|
||||
export default function getUserRoutes() {
|
||||
const router = express.Router();
|
||||
|
||||
// get user details based on id from token
|
||||
router.get("/", getUserDetails);
|
||||
router.get("/", authCheck, getUserDetails);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
async function getUserDetails(req: Request, res: Response) {
|
||||
console.log(req);
|
||||
|
||||
res.send({ message: "check" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user