I have an express backend to which I added Auth0. The problem is that whatever I do, I cannot get the callback route to work. I see it in my network tab, I can get it logged through my middleware on the server, but whatever I put into this route it is not executing. For debugging, I added a redirection and a console.log to /callback route but literally nothing happens after login and the auth0 is just redirecting to the origin of the request (for example when localhost8000/). Below is a truncated version of my server.ts Any help would be greatly appreciated. I’m stuck on this for the 3rd day and I’m losing my mind here.
const app: Express = express();
const port = 8000;
export const auth0Config: ConfigParams = {
authRequired: false,
auth0Logout: true,
secret: process.env.AUTH_SECRET,
baseURL: 'http://localhost:8000',
clientID: process.env.AUTH0_CLIENT_ID,
issuerBaseURL: process.env.AUTH0_DOMAIN,
session: {
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
},
rolling: true,
absoluteDuration: 86400, // 1 day
},
authorizationParams: {
scope: 'openid profile email',
},
};
app.use(express.urlencoded({ extended: false })); // required to handle urlencoded requests
app.use(express.json()); // required to handle form-data request
app.use(cors()); // middleware to enable CORS requests
// middleware to log request to the console
app.use((req, res, next) => {
console.log(`Request: ${req.method} ${req.url}`);
next();
});
app.use(auth(auth0Config));
app.post('/callback', (req, res) => {
console.log('Callback route reached - TEST 2');
res.redirect('http://localhost:3000');
});
app.get('/', (req, res) => {
res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out');
});
Here are my urls in Auth0 dashboard