# Next JS - Auth Section - Retrieve token api function - token is always null

**URL:** <https://forum.codewithmosh.com/t/next-js-auth-section-retrieve-token-api-function-token-is-always-null/23029>\
**Category:** React\
**Created:** [October 14, 2023, 9:44pm UTC](https://forum.codewithmosh.com/t/next-js-auth-section-retrieve-token-api-function-token-is-always-null/23029 "2023-10-14T21:44:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JerryHobby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jerryhobby/32/5370_2.png) [@JerryHobby](https://forum.codewithmosh.com/u/JerryHobby)\
**Post date:** [October 14, 2023, 9:44pm UTC](https://forum.codewithmosh.com/t/next-js-auth-section-retrieve-token-api-function-token-is-always-null/23029/1 "2023-10-14T21:44:10Z")

</div>

Implemented code to display next-auth token. When coded exactly like Mosh’s video, it produces an error regarding the return being an object {}. While debugging, I see that getToken always returns null. (screenshot line 9).

I can see the auth cookies in my application tab.

Also, when using the NextResponse.json() method on the return, it always produces this error.

> oopsie Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.

I can correct that by using JSON Stringify first. But I think the issue is caused by the empty token object. Regardless, the primary issue is that getToken() always returns null and I can’t figure out why.

While this demo function is only for fun - I just feel like auth is not working throughout the app and this is just a symptom. Anyone have any ideas?

Jerry  
#TypeScript #React #Next.js #next @mosh

 ![Screenshot 2023-10-14 at 4.24.15 PM](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/f/f49320a01c810e091fb17731fbb9b16d4bec58b4.png)

---

<div class="post-metadata">

**Author:** ![JerryHobby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jerryhobby/32/5370_2.png) [@JerryHobby](https://forum.codewithmosh.com/u/JerryHobby)\
**Post date:** [October 15, 2023, 2:35am UTC](https://forum.codewithmosh.com/t/next-js-auth-section-retrieve-token-api-function-token-is-always-null/23029/2 "2023-10-15T02:35:30Z")

</div>

SOLVED!

After 100,000 hours of testing and trial/error, I discovered that I named my file page.tsx. It needed to be route.tsx. Once I renamed it all worked perfectly.

I will leave this embarrassment here in case it helps someone else.

As an aside — as a 35 year veteran programmer … things go wrong for all of us.
