Problems setting up nuxt-auth-utils using custom provider

I'm having issues with this today. I followed @Atinux 's suggestion, and it seems to "want" to work, but it's creating excessive redirects, and on the Nuxt server logs it shows that it cannot find the env variables (even though I've added them), and it also logs that the callback url does not exist (even though I added it to /server/api/auth/custom-provider). I created the files in the suggestion, and they seem to be getting used, but my guess is that something is not configured correctly in nuxt.conf.ts In oauth key I have the following
{
['custom-provider']: {
authorizationParams: {
response_type: 'code',
scope: 'profile email',
},
authorizationUrl: `${process.env.OAUTH_BASE}/oauth/authorize`,
baseURL: process.env.AUTH_ORIGIN,
clientId: config.clientId,
clientSecret: config.clientSecret,
redirectURL: `${process.env.AUTH_ORIGIN}/api/auth/custom-provider`,
scope: ['profile', 'email'],
tokenUrl: `${process.env.OAUTH_BASE}/oauth/token`,
},
}
{
['custom-provider']: {
authorizationParams: {
response_type: 'code',
scope: 'profile email',
},
authorizationUrl: `${process.env.OAUTH_BASE}/oauth/authorize`,
baseURL: process.env.AUTH_ORIGIN,
clientId: config.clientId,
clientSecret: config.clientSecret,
redirectURL: `${process.env.AUTH_ORIGIN}/api/auth/custom-provider`,
scope: ['profile', 'email'],
tokenUrl: `${process.env.OAUTH_BASE}/oauth/token`,
},
}
So either something is not configured correctly, or the code in the custom files is incorrect somewhere. Any suggestions on how it needs to be set up to get it working? Does anyone have it working with a custom oauth provider (NOT the out-of-the-box ones listed in the documentation page) and would be able to share sample code?
GitHub
Issues · atinux/nuxt-auth-utils
Add Authentication to Nuxt applications with secured & sealed cookies sessions. - Issues · atinux/nuxt-auth-utils
2 Replies
kapa.ai
kapa.ai6d ago
Hi @luisfrocha. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- It sounds like you’re encountering two main issues with nuxt-auth-utils and a custom OAuth provider: excessive redirects and missing environment variables, as well as callback URL issues. 1. Environment Variables Not Found Nuxt 3 has built-in dotenv support. Your .env file should be at the project root and use the format KEY=VALUE. These variables are loaded automatically in dev, build, and generate modes. If your Nuxt server logs show missing env variables, double-check: - The .env file is at the root. - The variable names match exactly (case-sensitive). - You’re referencing them correctly in nuxt.config.ts (e.g., process.env.OAUTH_BASE). - If using Docker or another container, ensure envs are set in your deployment config as well nuxt.config.ts won't read env variables > Nuxt3 .env. 2. Excessive Redirects Excessive redirects often indicate a session or authentication state issue. This can happen if: - The session cookie isn’t being set or read correctly (possibly due to missing env variables for secrets). - The callback route isn’t properly registered or isn’t returning the expected response. - SSR is enabled and causing multiple session checks (as seen in similar issues with other auth modules; disabling SSR resolved rapid session checks in some cases next-auth token is not persisting after refreshing token). 3. Callback URL Not Found Make sure your callback handler is correctly placed at /server/api/auth/custom-provider.ts and that it exports the expected handler. The callback URL in your provider config should match this route exactly. 4. Provider Configuration Your provider config looks mostly correct, but ensure all referenced env variables are available and that you’re not mixing up redirectURL and redirectUri (some libraries use different names). Also, ensure you’re passing the correct values for clientId and clientSecret. 5. General Troubleshooting Steps - Log out all env variables at runtime to confirm they’re loaded. - Check the Nuxt server logs for the exact error messages. - Try a minimal example or reference repo, such as atidone, which demonstrates OAuth with nuxt-auth-utils Sessions and Authentication. - If you’re using sealed cookies for sessions, ensure NUXT_SESSION_PASSWORD is set and at least 32 characters long Sessions and Authentication. 6. Custom Provider Support The official documentation suggests that you can add custom OAuth providers, but there isn’t a detailed example for a fully custom provider in the knowledge sources. The nuxt-auth-utils README may have more up-to-date info, but it’s not included in the provided sources. --- Summary:
- Double-check your .env file and variable usage. - Ensure your callback route is correctly set up and matches the provider config. - Consider disabling SSR if you see rapid session checks. - Reference the atidone example repo for a working OAuth setup. - If issues persist, provide more detailed logs or minimal reproduction for further help. The knowledge sources do not contain a full working example of nuxt-auth-utils with a custom OAuth provider, so if you need a code sample, you may need to refer to the module’s GitHub issues or community discussions for more specific guidance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6d ago
<@371351227839152128> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?