# Await getAccessToken() fails with "TypeError: Failed to parse URL from /auth/access-token"

**URL:** <https://community.auth0.com/t/await-getaccesstoken-fails-with-typeerror-failed-to-parse-url-from-auth-access-token/152109>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-react\
**Created:** [November 21, 2024, 8:12pm UTC](https://community.auth0.com/t/await-getaccesstoken-fails-with-typeerror-failed-to-parse-url-from-auth-access-token/152109 "2024-11-21T20:12:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspencer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jspencer/32/62393_2.png) [@jspencer](https://community.auth0.com/u/jspencer)\
**Post date:** [November 21, 2024, 8:12pm UTC](https://community.auth0.com/t/await-getaccesstoken-fails-with-typeerror-failed-to-parse-url-from-auth-access-token/152109/1 "2024-11-21T20:12:01Z")

</div>

Ready to post? 🔍 First, try searching for your answer.  
Hi,  
I’m using “@auth0/nextjs-auth0”: “^4.0.0-beta.7” to sign in and get an access token.

The sign in is completing however, when I try to use the following from the [docs](https://github.com/auth0/nextjs-auth0/tree/v4?tab=readme-ov-file#getting-an-access-token):  
`const token = await getAccessToken()`  
I get an error:  
`TypeError: Failed to parse URL from /auth/access-token`

I have logged out my auth0 object in my middleware, but I don’t know what is relevant to post here.

---

<div class="post-metadata">

**Author:** ![jspencer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jspencer/32/62393_2.png) [@jspencer](https://community.auth0.com/u/jspencer)\
**Post date:** [November 21, 2024, 8:18pm UTC](https://community.auth0.com/t/await-getaccesstoken-fails-with-typeerror-failed-to-parse-url-from-auth-access-token/152109/2 "2024-11-21T20:18:22Z")

</div>

Looking at the source of get-access-token.js:

```auto
export async function getAccessToken() {
    // TODO: cache response and invalidate according to expiresAt
    const tokenRes = await fetch("/auth/access-token").then((res) => res.json());
    return tokenRes.token;
}

```

it looks like there is a base url missing.

---

<div class="post-metadata">

**Author:** ![jspencer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jspencer/32/62393_2.png) [@jspencer](https://community.auth0.com/u/jspencer)\
**Post date:** [November 21, 2024, 8:29pm UTC](https://community.auth0.com/t/await-getaccesstoken-fails-with-typeerror-failed-to-parse-url-from-auth-access-token/152109/3 "2024-11-21T20:29:17Z")

</div>

I solved this by using the correct endpoint 🙂

```auto
		const session = await auth0.getSession()
		// Get the access token
		console.log('Extracting Access token')
		const accessToken = session?.tokenSet.accessToken

```

---

<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:** [April 23, 2025, 1:52pm UTC](https://community.auth0.com/t/await-getaccesstoken-fails-with-typeerror-failed-to-parse-url-from-auth-access-token/152109/4 "2025-04-23T13:52:37Z")

</div>

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