Currently I have a backend where I am able to verify access tokens with this simple function:
const { verify } = require("jsonwebtoken");
const isAuth = req => {
const authorization = req.headers["authorization"];
if (!authorization) throw new Error("You need to login");
const token = authorization.split(" ")[1]; //Bearer token123123jjjjasd , we get the token value
const { userId } = verify(token, process.env.ACCESS_TOKEN_SECRET);
return userId;
};
module.exports = {
isAuth
};
But what about doing that in the front side / react to protect my routes? Isn't it dangerous to store the secret in my front end? Should i create a verification route in my backend and send there the access tokens and return true if valid, or else false? Would that be secure?