# NextJS + Vercel Application: api/auth/callback failing despite succeeding locally

**URL:** <https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, nextjs-auth0\
**Created:** [February 11, 2023, 12:37am UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233 "2023-02-11T00:37:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![spencer1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/spencer1/32/44553_2.png) [@spencer1](https://community.auth0.com/u/spencer1)\
**Post date:** [February 11, 2023, 12:37am UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/1 "2023-02-11T00:37:22Z")

</div>

Hey Auth0 team!

I’ve been banging my head against the wall in search of a solution to an issue I’m having getting the callbacks to to work in production after login and logout. It seems that both the login and logout functions are working in both environments but on redirect I’m consistently getting an error in production. Some context first on what I’ve tried:

I have an application built with NextJS that uses the Auth0 SDK for user registration and login. It’s been working well locally and has historically worked well upon deployment to Vercel. Today, it stopped working in “production” on Vercel. I’ve done the following to troubleshoot but can’t quite track down the root cause:

1. Moved all of my production environment variables into Vercel. This is what my .env.production file in my repo looks like currently.

```auto
AUTH0_SECRET=${AUTH0_SECRET}
AUTH0_BASE_URL=${AUTH0_BASE_URL}
AUTH0_ISSUER_BASE_URL='https://dev-34dtsap5c884eh3q.us.auth0.com'
AUTH0_CLIENT_ID=${AUTH0_CLIENT_ID}
AUTH0_CLIENT_SECRET=${AUTH0_CLIENT_SECRET}

```

1. Created a separate Auth0 application for the Vercel environment. With the following Application URIs:

- Allowed Callback URLs: [https://tandem-five.vercel.app/api/auth/callback](https://tandem-five.vercel.app/api/auth/callback)
- Allowed Logout URLs: [https://tandem-five.vercel.app/](https://tandem-five.vercel.app/)

Here is the Auth0 file for reference:

**/src/pages/api/auth/[…auth0].js**

```auto
import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

export default handleAuth({
  onError(req, res, error) {
    console.log(error);
    console.log(req)
    res.status(error.status || 500).end('Check the console for the error');
  }
});

```

I’m sure there’s a straightforward reason - but I haven’t found it yet in my attempts to fix and in the other articles with similar subjects. If there’s any guidance on troubleshooting on my own further, please let me know. Otherwise, any guidance on a potential root cause would help!

Thanks

---

<div class="post-metadata">

**Author:** ![dev38](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dev38/32/33281_2.png) [@dev38](https://community.auth0.com/u/dev38)\
**Post date:** [February 11, 2023, 2:14pm UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/2 "2023-02-11T14:14:11Z")

</div>

Hello there!

I’m facing the same issue, it seems to be coming out of nowhere.  
One thing that is odd tho’ is that we have a staging environment that shares the same Auth0’s configuration and for which everything works just fine.

So it might be an environment based issue.

---

<div class="post-metadata">

**Author:** ![dev38](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dev38/32/33281_2.png) [@dev38](https://community.auth0.com/u/dev38)\
**Post date:** [February 11, 2023, 2:15pm UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/3 "2023-02-11T14:15:47Z")

</div>

Update !  
I’ve updated the NPM Packages and it works!

From :

- “auth0”: “^3.0.1”
- “@auth0/nextjs-auth0”: “^2.0.1”

To :

- “auth0”: “^3.2.0”
- “@auth0/nextjs-auth0”: “^2.2.1”

---

<div class="post-metadata">

**Author:** ![spencer1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/spencer1/32/44553_2.png) [@spencer1](https://community.auth0.com/u/spencer1)\
**Post date:** [February 11, 2023, 6:54pm UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/4 "2023-02-11T18:54:39Z")

</div>

Hey! Awesome; thanks so much for the response. Uninstalling both packages and re-installing them did the trick.

Thanks again!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [February 22, 2023, 11:56am UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/5 "2023-02-22T11:56:34Z")

</div>

Thanks everyone for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 8, 2023, 11:57am UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/6 "2023-03-08T11:57:31Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [July 31, 2024, 9:08pm UTC](https://community.auth0.com/t/nextjs-vercel-application-api-auth-callback-failing-despite-succeeding-locally/100233/7 "2024-07-31T21:08:20Z")

</div>

Hey team!

This topic seems related to the new [Auth0 Integration](https://auth0.com/blog/auth0-vercel-integration/) available new in [Vercel Marketplace](https://vercel.com/integrations/auth0). This is the first version of this integration, and we welcome your feedback to improve future iterations.

You’ll need an [existing Vercel project](https://vercel.com/docs/projects/overview) to use the new integration to build and customize the Identity flow. You can either import your project into Vercel or use a Vercel template so you don’t have to start from scratch like our SaaStart template to deploy a production-ready B2B SaaS app in minutes (learn more [here](https://auth0.com/blog/speed-up-your-customer-identity-journey-with-auth0-saastart/)).

If you find yourself having questions regarding this new integration for the next two weeks, we are hosting an [Ask Me Anything session](https://community.auth0.com/t/auth0-community-ask-me-anything-integrating-auth0-within-the-vercel-marketplace/136388). Our Product Expert will provide comprehensive written answers on August 8th from 8 AM to 10 AM PST.

Find out more about [Auth0 Integration](https://auth0.com/blog/auth0-vercel-integration/) and [learn more about AMA](https://community.auth0.com/t/auth0-community-ask-me-anything-integrating-auth0-within-the-vercel-marketplace/136388).

Thanks!  
Dawid
