# Nextjs-auth0 - 401 Error when not logged in?

**URL:** <https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311>\
**Category:** Get Help\
**Created:** [July 2, 2022, 11:50am UTC](https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311 "2022-07-02T11:50:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![weidenhaus](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/weidenhaus/32/38532_2.png) [@weidenhaus](https://community.auth0.com/u/weidenhaus)\
**Post date:** [July 2, 2022, 11:50am UTC](https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311/1 "2022-07-02T11:50:49Z")

</div>

Hello folks,

Just created the nextjs-aut0 example app based on the steps in the readme here: [GitHub - auth0/nextjs-auth0: Next.js SDK for signing in with Auth0](https://github.com/auth0/nextjs-auth0)

Now when I’m not logged in, it still calls the auth/me route and I get a 401. Is there a better way to check if I’m logged in without actually trying to read user data and responding with a 401?

Thank you so much!

- Which SDK this is regarding: @auth0/nextjs-auth0
- SDK Version: 1.9.1
- Platform Version: “next”: “12.2.0”, “react”: “18.2.0”,
- Code Snippets/Error Messages/Supporting Details/Screenshots:  
 ![Screen Shot 2022-07-02 at 9.47.15 pm](https://global.discourse-cdn.com/auth0/original/3X/f/e/fedb83d417bdc84f491c37eb13d6f4c9094dcb0f.jpeg)

---

<div class="post-metadata">

**Author:** ![dylan6](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dylan6/32/33703_2.png) [@dylan6](https://community.auth0.com/u/dylan6)\
**Post date:** [September 20, 2022, 3:03pm UTC](https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311/3 "2022-09-20T15:03:01Z")

</div>

Encountering same issue

---

<div class="post-metadata">

**Author:** ![jack6](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack6/32/33232_2.png) [@jack6](https://community.auth0.com/u/jack6)\
**Post date:** [October 11, 2022, 9:35pm UTC](https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311/4 "2022-10-11T21:35:37Z")

</div>

did u find a solution for this ?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [October 11, 2022, 10:46pm UTC](https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311/6 "2022-10-11T22:46:48Z")

</div>

Hey all! For future reference please see:

> [@401 Unauthorized issue at /api/auth/me!](https://community.auth0.com/t/401-unauthorized-issue-at-api-auth-me/89761/5):
>
> Hey there @jack6! This is expected behavior - The front end uses /api/auth/me endpoint to check if the user is authenticated or not (401 = logged out, 200 = logged in). You could technically adjust the profile handler to not return 401, but this would also require you to write your own front end code to get the user sessions since the useUser hook expects that API to respond with a 401 if the user is unauthenticated. Given this has surfaced multiple times already, I definitely recommend creati…

---

<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:** [October 25, 2022, 10:47pm UTC](https://community.auth0.com/t/nextjs-auth0-401-error-when-not-logged-in/86311/7 "2022-10-25T22:47:12Z")

</div>

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