You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nest-Auth0: Empty req Object on /api/auth/callback?code in Production
Setup:
Node.js Version: 18
Package Manager: Yarn
Framework: Next.js (using nest-auth0 package)
Server: EC2 Ubuntu with Nginx as a reverse proxy
Issue:
I’m encountering a 502 Bad Gateway error on the /api/auth/callback?code endpoint when trying to sign up a user in production (yarn build + yarn start). The same functionality works perfectly in development mode (yarn dev).
Upon investigation, I found that in production, the entire req object is empty when the callback route is triggered. For other routes like /api/auth/login or /api/auth/logout, req is populated as expected.
I've already tried several solutions from online resources, including updating the Nginx configuration, but the problem persists.
Code Snippet:
The issue occurs in the callback handler in this function:
function handlerFactory({ handleLogin, handleLogout, handleCallback, handleProfile }) {
return (userHandlers = {}) => {
const { login, logout, callback, profile } = Object.assign({
login: wrapErrorHandling(handleLogin),
logout: wrapErrorHandling(handleLogout),
callback: wrapErrorHandling(handleCallback),
profile: wrapErrorHandling(handleProfile),
}, userHandlers);
return async (req, res) => {
console.log(req); // Logs {} for the callback route in production
let { query: { auth0: route } } = req; // Fails due to empty req object
route = Array.isArray(route) ? route[0] : route;
switch (route) {
case 'login':
return login(req, res);
case 'logout':
return logout(req, res);
case 'callback':
return callback(req, res);
case 'me':
return profile(req, res);
default:
res.status(404).end();
}
};
};
}
Error:
/home/ubuntu/crux-ui-app/packages/frontend/.next/server/chunks/462.js:1189
let { query: { auth0: route } } = req;
^
TypeError: Cannot read properties of undefined (reading 'auth0')
When I print req for /api/auth/callback?code=..., it logs {}. This issue is only for the callback route. Other routes (login, logout, me) work fine in production.
What I've Tried:
Updating Nginx Config: Added proxy_buffering off, proxy_request_buffering off, and other settings to ensure proper request forwarding also tried increasing size of buffers.
Testing Without Nginx: Stopped Nginx and directly accessed the Next.js server on port 5020. The issue still persists.
Environment Variables: Verified that all necessary environment variables are set correctly in production.
Manual Request Parsing: Attempted to manually parse the query string using url.parse(req.url, true), but since req is empty, this approach also fails.
Observations:
In development (yarn dev), everything works as expected.
Previously, I faced a similar issue with the logout route, which was resolved by replacing the Link tag with an tag in the component. However, this workaround doesn’t apply to the signup flow.
Request for Help:
Does anyone know why the req object might be empty for the callback route in production or how to debug this further? Any insights on how to resolve this issue would be greatly appreciated!
Reproduction
Unsure about reproduction
Additional context
No response
nextjs-auth0 version
3.5.0
Next.js version
12.0.7
Node.js version
18
The text was updated successfully, but these errors were encountered:
Description
Nest-Auth0: Empty req Object on /api/auth/callback?code in Production
Setup:
Node.js Version: 18
Package Manager: Yarn
Framework: Next.js (using nest-auth0 package)
Server: EC2 Ubuntu with Nginx as a reverse proxy
Issue:
I’m encountering a 502 Bad Gateway error on the /api/auth/callback?code endpoint when trying to sign up a user in production (yarn build + yarn start). The same functionality works perfectly in development mode (yarn dev).
Upon investigation, I found that in production, the entire req object is empty when the callback route is triggered. For other routes like /api/auth/login or /api/auth/logout, req is populated as expected.
I've already tried several solutions from online resources, including updating the Nginx configuration, but the problem persists.
Code Snippet:
The issue occurs in the callback handler in this function:
Error:
When I print req for /api/auth/callback?code=..., it logs {}. This issue is only for the callback route. Other routes (login, logout, me) work fine in production.
What I've Tried:
Updating Nginx Config: Added proxy_buffering off, proxy_request_buffering off, and other settings to ensure proper request forwarding also tried increasing size of buffers.
Testing Without Nginx: Stopped Nginx and directly accessed the Next.js server on port 5020. The issue still persists.
Environment Variables: Verified that all necessary environment variables are set correctly in production.
Manual Request Parsing: Attempted to manually parse the query string using url.parse(req.url, true), but since req is empty, this approach also fails.
Observations:
In development (yarn dev), everything works as expected.
Previously, I faced a similar issue with the logout route, which was resolved by replacing the Link tag with an tag in the component. However, this workaround doesn’t apply to the signup flow.
Request for Help:
Does anyone know why the req object might be empty for the callback route in production or how to debug this further? Any insights on how to resolve this issue would be greatly appreciated!
Reproduction
Unsure about reproduction
Additional context
No response
nextjs-auth0 version
3.5.0
Next.js version
12.0.7
Node.js version
18
The text was updated successfully, but these errors were encountered: