# Next.js Vercel access\_denied (unauthorized)

**URL:** <https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865>\
**Category:** Get Help\
**Tags:** typescript, nextjs, login, auth0\
**Created:** [June 22, 2021, 4:22pm UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865 "2021-06-22T16:22:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blazestudios23](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/blazestudios23/32/30151_2.png) [@blazestudios23](https://community.auth0.com/u/blazestudios23)\
**Post date:** [June 22, 2021, 4:22pm UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865/1 "2021-06-22T16:22:35Z")

</div>

Bug report

Using:

“@auth0/nextjs-auth0”: “1.3.1”,  
“next”: “latest”,  
“react”: “17.0.2”,  
“react-dom”: “17.0.2”,  
“typescript”: “^4.3.3”

This is running on node 14.

my directory is pages/api/auth/[…auth0].ts

[…auth0].ts contains:

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

export default handleAuth();

```

After signing on with google or twitter, it returns to the [https://domain/api/auth/callback](https://domain/api/auth/callback)  
and I get the following error message:

access\_denied (Unauthorized)

I do not get that error in my local environment, everything works there. I am hosting with Vercel and get this error in that hosting environment. It’s possible that there is some kind of .env secret that is miss configured. Or that the server less function calling this is not passing something correctly to Auth0.

I really need some help on this, so any advice is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [June 22, 2021, 4:57pm UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865/3 "2021-06-22T16:57:33Z")

</div>

Hi @blazestudios23,

Welcome to the Community!

We have an FAQ that might be related to this error:  
[https://community.auth0.com/t/why-am-i-getting-an-access-denied-error/63027](https://community.auth0.com/t/why-am-i-getting-an-access-denied-error/63027)

Also, I found this Github issue in the nextjs-auth0 repo. In this case, the social connection did not work because of the env vars that were configured:

> <https://github.com/auth0/nextjs-auth0/issues/66>
>
> \### Description
> I am using the sample Next.js Auth0 application and I added Git…Hub authentication, but unfortunately it always returns \`Unauthorized\`.
> 
> \### Reproduction
> 
> \- \`npx create-next-app --example auth0 auth\`
> \- \`cd auth0\`
> \- \`npm i\`
> \- \`cp .env.template .env\`
> \- I have setup a GitHub Application and enabled the social connection
> \- Click on Login
> \- Select 'GitHub'
> \- Observe 'Unauthorized'
> 
> FYI I am \*not\* using a custom domain. My GitHub app settings are:
> 
> Homepage URL: \`https://mytenantname.auth0.com\`
> Authorization callback URL: \`https://mytenantname.auth0.com/api/callback\`
> 
> My \`.env\` file:
> \`\`\`
> AUTH0\_CLIENT\_ID=XXX
> AUTH0\_DOMAIN=mytenantname.auth0.com
> AUTH0\_CLIENT\_SECRET=ABC
> REDIRECT\_URI=http://localhost:3000/api/callback
> POST\_LOGOUT\_REDIRECT\_URI=http://localhost:3000/
> SESSION\_COOKIE\_SECRET=123
> \`\`\`
> 
> Please note that I have also tried to change the GitHub Application settings from the tenant name to \`http://localhost:3000\` and \`http://localhost:3000/api/callback\` but in that case I am getting the following error:
> 
> \`state mismatch, expected long-random-string, got: another-long-random-string\`
> 
> Plus the following message in the console: \`The redirect\_uri MUST match the registered callback URL for this application.\`
> 
> \### Environment
> 
> \> Please provide the following:
> 
> \- 0.6.0
> \- next: "latest"
> \- Mac/Chrome latest

Hopefully, those resources will help you get past the error!

---

<div class="post-metadata">

**Author:** ![blazestudios23](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/blazestudios23/32/30151_2.png) [@blazestudios23](https://community.auth0.com/u/blazestudios23)\
**Post date:** [June 22, 2021, 8:05pm UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865/4 "2021-06-22T20:05:17Z")

</div>

I’ve already read both of these and neither resolved the issue that I’m facing.

---

<div class="post-metadata">

**Author:** ![blazestudios23](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/blazestudios23/32/30151_2.png) [@blazestudios23](https://community.auth0.com/u/blazestudios23)\
**Post date:** [June 23, 2021, 5:37am UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865/5 "2021-06-23T05:37:07Z")

</div>

I found the issue. I had:

`AUTH0_SCOPE= "openid email profile"`

in Vercel.

Changing it to:

`AUTH0_SCOPE=openid email profile`

Fixed the problem.

The issue was caused by quotation marks in the environment variable.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [June 23, 2021, 1:56pm UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865/6 "2021-06-23T13:56:27Z")

</div>

Glad to hear you were able to resolve it. Thanks for sharing your solution!

---

<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:** [June 28, 2021, 11:47am UTC](https://community.auth0.com/t/next-js-vercel-access-denied-unauthorized/64865/7 "2021-06-28T11:47:51Z")

</div>


