I am trying to setup a backend and use an expressJwt middleware but keep getting the error “jwt malformed”. Even though, as you can see in my screenshot, my token format is correct with “Bearer [token]”.
This is running on a simple express.js server and I am getting the error “UnauthorizedErrorL jwt malformed”
import dotenv from 'dotenv';
import express from 'express';
import authRouter from './api/auth';
import { expressjwt, GetVerificationKey } from 'express-jwt';
import jwksRsa from 'jwks-rsa';
dotenv.config();
const app = express();
app.use(express.json());
app.use(
expressjwt({
secret: jwksRsa.expressJwtSecret({
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`, // JWKS URL from Auth0
}) as GetVerificationKey ,
algorithms: ['RS256'],
audience: process.env.AUTH0_AUDIENCE,
issuer: `https://${process.env.AUTH0_DOMAIN}/`,
}).unless({ path: ['/login', '/signup'] })
);
app.use('/auth', authRouter);
// Define the port
const PORT = process.env.PORT || 3000;
// Start the server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});