# Next.js Auth0 v4: successful login followed by token exchange HTTP 401 access\_denied

**URL:** <https://community.auth0.com/t/next-js-auth0-v4-successful-login-followed-by-token-exchange-http-401-access-denied/206133>\
**Category:** Get Help\
**Tags:** authentication, nextjs\
**Created:** [December 2, 2026, 11:51am UTC](https://community.auth0.com/t/next-js-auth0-v4-successful-login-followed-by-token-exchange-http-401-access-denied/206133 "2026-12-02T11:51:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![management](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/management/32/81328_2.png) [@management](https://community.auth0.com/u/management)\
**Post date:** [December 2, 2026, 11:51am UTC](https://community.auth0.com/t/next-js-auth0-v4-successful-login-followed-by-token-exchange-http-401-access-denied/206133/1 "2026-12-02T11:51:01Z")

</div>

We’re testing an isolated, nonproduction Next.js dashboard on Railway. User authentication succeeds, but the callback displays:

> An error occurred while trying to exchange the authorization code.

A bounded diagnostic wrapper captured:

```json
{"http_status":401,"oauth_error":"access_denied"}

```

Auth0 logs show **Success Login** , followed immediately by **Failed Exchange (feacft) — Unauthorized**. The event’s context provides no additional rejection reason.

Environment:

- Node.js 22.23.5
- Next.js 16.2.11
- `@auth0/nextjs-auth0` 4.28.0
- Regular Web Application using Client Secret (Post)

Checks completed:

- Deployment client ID and domain match the intended application.
- Owner privately compared both current and retained deployment secrets with Auth0 and reported exact matches.
- Authorization Code grant is enabled.
- OIDC identification is enabled and openid profile email are permitted.
- Exact callback URLs were configured during testing.
- No additional security-denial event appeared in the same-client, three-minute log window.

The SDK uses its default callback/session handling, without a client-authentication override. The diagnostic wrapper forwards the existing request once and returns the original response; it adds no retry.

**What further read-only evidence would distinguish the cause of this specific token-endpoint rejection without rotating secrets, weakening authentication or repeatedly deploying?**

The trial services are offline. No credentials, tokens, authorization codes, tenant/client/log identifiers or raw logs are included.
