Hi,
I followed the React Authentication By Example: Using React Router 6 guide here(React Authentication By Example: Using React Router 6)
Everything is working perfect until the point in which… I try to use a NodeJS Express server."
Since the guide only works for Single Page Web Applications… I’m wondering if that is the problem.
When I go to the Settings on a Regular Web Application, on the Quick Start guide, it gives me the Integrate Auth0 option by installing express. Then it gives me this example code:
const { auth } = require(‘express-openid-connect’);
const config = {
authRequired: false,
auth0Logout: true,
secret: ‘a long, randomly-generated string stored in env’,
baseURL: ‘http://localhost:4040’,
clientID: ‘clientID’,
issuerBaseURL: ‘https://RANDOM.URL’
};
// auth router attaches /login, /logout, and /callback routes to the baseURL
app.use(auth(config));
// req.isAuthenticated is provided from the auth router
app.get(‘/’, (req, res) => {
res.send(req.oidc.isAuthenticated() ? ‘Logged in’ : ‘Logged out’);
});
This does not happen on the Single Page Web Application. And I’m wondering if this is not allowing me to be able to use ‘express-openid-connect’.
Every time I try to use it… it gives me a 401 (Unauthorized) error when using an axios.get function.
Then on the Network tab, the response I get is “jwt malformed”.
I’ve checked all these settings on my index.js file on the server folder:
const { auth } = require(‘express-openid-connect’);
const verifyJWT = jwt({
secret: jwks.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: ‘https://randomURL.us.auth0.com/.well-known/jwks.json’
}),
audience: ‘https://randomURL’,
issuer: ‘https://randomURL.us.auth0.com’,
algorithms: [‘RS256’]
}).unless({path: [‘/’]})
app.use(verifyJWT);
const config = {
authRequired: false,
auth0Logout: true,
secret: process.env.secret,
baseURL: ‘http://localhost:4040/’,
clientID: ‘clientID’,
issuerBaseURL: ‘https://randomURL.us.auth0.com’
};
app.use(auth(config));
I can’t seem to see the problem.