Problem with auth/callback when next.js app deployed on Azure app service #3739
-
Question 💬Hi, I am trying to make working next-auth when deploying my Next.js app on Azure app service. Locally everything works fine. OIDC provider like: {
clientId: 'react',
id: 'oidc-custom',
name: 'oidc-custom',
type: 'oauth',
idToken: true,
// @ts-ignore
wellKnown: `${ACCOUNT_API_URL}/.well-known/openid-configuration`,
// @ts-ignore
clientSecret: CLIENT_APP_CODE,
authorization: {
// @ts-ignore
url: `${ACCOUNT_API_URL}/connect/authorize`,
params: {
scope: 'openid email profile roles',
prompt: 'login',
// @ts-ignore
redirect_uri: `${NEXTAUTH_URL}/api/auth/callback/oidc-custom` //I have tried also without this redirect_uri
}
}, package.json "main": "server.js",
"scripts": {
"dev": "next dev",
"build": "next build",
"build:qa": "cross-env NODE_ENV=production BUILD_ENV=qa next build",
"build:production": "cross-env NODE_ENV=production BUILD_ENV=production next build",
"start": "cross-env NEXTAUTH_URL=https://MY-APP-qa-next.azurewebsites.net node server.js",
},
"dependencies": {
"next": "^12.0.7",
"next-auth": "^4.0.5",
} server.js const { createServer } = require('http');
const next = require('next');
const port = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
handle(req, res);
}).listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on <http://localhost>:${port}`);
});
}); web.config
In general web.config and server.js are taken from How to reproduce ☕️So after deployment to azure app service next.js is working fine (pages, SSR, rewrites, i18n), but when I am trying to login then I have flow like
So this step no. 11 is to localhost with payload OAuthCallback error. No idea from where it comes from When I run this locally (yarn run dev), then first ten steps are exactly the same and login is successfully done. Any idea what can be missing? Contributing 🙌🏽No, I am afraid I cannot help regarding this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, I was looking for solution for this issue for last two days. And now, when I posted it here I have tried one more thing. According to https://next-auth.js.org/getting-started/example#deploying-to-production I have added NEXTAUTH_URL as application setting under app service configuration. package.json
Maybe this will work for regular server, but looks like Azure app service need to have NEXTAUTH_URL set in application setting. |
Beta Was this translation helpful? Give feedback.
Hi,
I was looking for solution for this issue for last two days. And now, when I posted it here I have tried one more thing. According to https://next-auth.js.org/getting-started/example#deploying-to-production I have added NEXTAUTH_URL as application setting under app service configuration.
Earlier I thought that something like below will be sufficient.
package.json
Maybe this will work for regular server, but looks like Azure app service need to have NEXTAUTH_URL set in application setting.
So looks like problem solved.