Nathaly Toledo
KKinde
•Created by Rinzarin on 4/19/2025 in #💻┃support
Error: State not Found
How to fix it:
✅ Ensure all domains match:
- The domain you start the auth flow on must match the domains in KINDE_SITE_URL and KINDE_POST_LOGIN_REDIRECT_URL. I would check this via the Network tab of the Developer Tools of your browser to confirm that I am being redirected to the same app/domain when the callback happens.
✅ Dynamically set environment variables for Firebase preview/production deployments. I have attached the guide for Next.js that shows you an example of this.
Unlikely but could be tested
I would recommend having different paths for the login and redirect URLs, such as:
KINDE_SITE_URL=http://localhost:3000
KINDE_POST_LOGIN_REDIRECT_URL=http://localhost:3000/dashboard
Source:
https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk/#state-not-found-error
Let me know if these help!8 replies
KKinde
•Created by Rinzarin on 4/19/2025 in #💻┃support
Error: State not Found
Hello, @Rinzarin.
I have investigated your issue and these are the two most likely causes:
The error normally occurs because the domain where you start the authentication flow (e.g., https://your-app.firebaseapp.com) doesn’t match the domain you’re redirected to after logging in (e.g., https://your-production-domain.com). Here’s what’s happening behind the scenes:
1. When you click "Login":
- A unique "state" cookie is saved in your browser, tied to the initial domain (e.g., your-preview-domain.web.app).
- Your app redirects you to Kinde’s login page.
2. After logging in:
- Kinde tries to send you back to your app’s callback URL (e.g., your-production-domain.com/api/auth/kinde_callback).
- Your app checks if the "state" cookie (from step 1) exists on the domain you’re redirected to.
3. The problem:
- If the callback domain (where you’re redirected) doesn’t match the initial domain (where you started the flow), the browser can’t find the "state" cookie.
- This mismatch causes the error, as the auth flow aborts for security reasons.
- Hardcoded environment variables:
If KINDE_SITE_URL or KINDE_POST_LOGIN_REDIRECT_URL are set to a static domain (e.g., your production URL), but you’re testing on a Firebase preview domain (e.g., your-project-id.web.app), the redirect will fail.
- Multiple environments (staging/production):
If you deploy to different Firebase Hosting channels (e.g., staging vs. production) but don’t update environment variables for each, domains will mismatch.
8 replies
KKinde
•Created by Marcin on 3/25/2025 in #💻┃support
Kinde Auth Callback Issue on my domain
3. Additional recommendation:
Using wildcards for production introduces some security risks, so this is suggested for non-production environments only.
We recommend using wildcards only for non-production purposes, as they present increased security risk.A more secure way of managing dynamic wildcards is to integrate with the Kinde Management API and manage them via API calls. There is a dedicated documentation page for this that happens to be focused on Vercel and Next.js. This is the link in case you are not already aware of it and feel interested: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk/#working-with-preview-urls Of course, it is up to you and what works for your case. Let me know if these helped so that I can assist your further in the case they were not helpful.
8 replies
KKinde
•Created by Marcin on 3/25/2025 in #💻┃support
Kinde Auth Callback Issue on my domain
2. Limitations with wildcards
From the code you shared, you seem to be using wildcards with your Vercel domain. Here are some notes to keep in mind, and I have highlighted the ones that may apply to your case given the details you shared:
- Root level domains are not allowed (.com is not allowed). - Only a single wildcard is allowed per callback (https://..hello.com is not allowed). - Wildcards are only allowed with http or https URL protocols (.hello.com, service:jmx:rmi://[host[:port]][urlPath] are not allowed). - Wildcard has to be in the leftmost subdomain (https://*.hello.com is allowed, https://hello.*.com is not allowed). - Wildcards with prefixes and suffixes are allowed (https://prefix-*-suffix.hello.com) - A URL with a valid wildcard will not match a URL with more than one subdomain level in place of the wildcard. (https://*.hello.com will not work with https://sub1.sub2.hello.com) - Certain well-known shared hosting domains require a suffix or prefix for the wildcard (*.vercel.app is not allowed as this opens up anyone to authenticate on the Vercel platform, but *something.vercel.app is allowed as this will lock callbacks to your team or personal account). - Wildcards are not supported as part of a URL path (https://sub1.sub2.hello.com/* is not allowed). You can use the post-login redirect (available in several SDKs) to achieve dynamic navigation after authentication.Source: https://docs.kinde.com/get-started/connect/callback-urls/#wildcard-limitations In the code you shared, one of your URLs match a case that is not allowed https://*.vercel.app/api/auth/kinde_callback , I would suggest changing it what the highlighted line recommends.
8 replies
KKinde
•Created by Marcin on 3/25/2025 in #💻┃support
Kinde Auth Callback Issue on my domain
Potential root causes:
The error seems to stem from limitations of wildcards [1], combined with potential middleware conflicts and/or Vercel data state [2].
Have you checked the common issues with invalid callback URLs?
Troubleshoot ‘Invalid callback URL’ - A common error reported by new users is that they receive an ‘invalid callback URL’ message when testing their connection. If you get this error, check the following: - Make sure there are no spaces before or after the callback URL in your Kinde application. - Ensure the callback URL in your code exactly matches the callback URL in your Kinde application. - The Client ID in your code must exactly match the Client ID in your Kinde application. - If you’re testing with a cloud hosting solution, such as Vercel, redeploy your application each time you update the environment variables.Source: https://docs.kinde.com/get-started/connect/callback-urls/ One possible scenario is that you deployed the site, and updated certain environment variables later, which is generating this issue as the "updated" environment variables may be the correct ones. Have you tested that this does not work after you redeploy your Vercel app with the updated code that works in localhost and correct environment variables?
8 replies
KKinde
•Created by Marcin on 3/25/2025 in #💻┃support
Kinde Auth Callback Issue on my domain
Hello Marcin. Thank you for the detailed debugging summary—it’s very helpful.
Since:
- The flow works locally, and
- Authentication succeeds in production (despite the callback error),
This suggests:
- No code/flow issues (as you noted).
- Unlikely to be a URL mismatch (Kinde’s UI usually flags this explicitly).
8 replies