nextjs-auth0: Auth0 login fails with '"secret" is required' when deployed to Netlify
Description
I have followed the Auth0 for Next.js instructions. This works fine locally, and I can sign in and out. ~I also need an email allowlist, so I’ve used the template “Whitelist” rule. My rule ended up locking out users who created an account without being on the allowlist, so I adapted code from this Community post to solve that problem.~ Update: I have turned off the Email Allowlist to simplify matters, but I still get the same error.
Everything works fine when I sign in locally. But when I deploy to Netlify and sign in, I get this error:
{
"errorType": "TypeError",
"errorMessage": "\"secret\" is required",
"trace": [
"TypeError: \"secret\" is required",
" at Object.get (/var/task/src/nextPage/index.js:25502:15)",
" at Object.getConfig (/var/task/src/nextPage/index.js:14641:40)",
" at Object.initAuth0 (/var/task/src/nextPage/index.js:46736:49)",
" at getInstance (/var/task/src/nextPage/index.js:46732:24)",
" at handleAuth (/var/task/src/nextPage/index.js:46784:33)",
" at Module.HJ75 (/var/task/src/nextPage/index.js:16032:134)",
" at __webpack_require__ (/var/task/src/nextPage/index.js:23:31)",
" at Module.JR3O (/var/task/src/nextPage/index.js:18752:23)",
" at __webpack_require__ (/var/task/src/nextPage/index.js:23:31)",
" at /var/task/src/nextPage/index.js:91:18"
]
}
I have these variables set in the Netlify environment:
AUTH0_SECRET='xxx'
AUTH0_BASE_URL='https://deployed-site-url.netlify.app'
AUTH0_ISSUER_BASE_URL='https://xxx-xxx-xxx.xx.auth0.com'
AUTH0_CLIENT_ID='xxx'
AUTH0_CLIENT_SECRET='xxx'
I have the same ones set locally using .env.local, but the AUTH0_BASE_URL is set to http://localhost:3000.
I’m never explicitly initing Auth0, I’m just using useUser and withPageAuthRequired as needed. My api/auth/[...auth0].js file looks the same as the tutorial:
import { handleAuth } from '@auth0/nextjs-auth0';
export default handleAuth();
What am I doing wrong??
Environment
Please provide the following:
- Version of this library used: @auth0/nextjs-auth0@1.3.0
- Version of the platform or framework used, if applicable: @next/env@10.0.9
- Other relevant versions (language, server software, OS, browser): Mac, but the same failure happens on Firefox and Brave (Chromium).
- Other modules/plugins/libraries that might be involved: Netlify
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (5 by maintainers)
Just to add in here, I was also getting this same error when deploying to vercel
i was having the same problem… make sure you have the file named
.env.localand notenv.local😃 i won’t say how long it took me to figure that one out lol…And make sure that the
.env.localfile is in the root of the project AND NOT IN THEsrcFILE! 😃Hi do you remember how you solved this?
Hii Answer (My Solution)
Don’t put the *(Auth0) Environmental variable in Next.config.js .env.local worked for me
Can you log that env var out in your handler to see if it’s set? Perhaps in the
api/auth/[...auth0].jsfileThanks for the reply. I have put the environment variables in the Build & deploy section of the Site settings.
The link you provide above says this should be sufficient:
I’ve included a “SECRET” variable as well, just to see if “AUTH0_” was causing the issue. This didn’t change anything, though.
Is there a way to get more verbose logging in the
next_api_auth_auth0function which is running the SDK code?