# @auth0/nextjs-auth0 calling me prior to login

**URL:** <https://community.auth0.com/t/auth0-nextjs-auth0-calling-me-prior-to-login/63244>\
**Category:** Get Help\
**Tags:** nextjs, login, auth0\
**Created:** [May 24, 2021, 4:08am UTC](https://community.auth0.com/t/auth0-nextjs-auth0-calling-me-prior-to-login/63244 "2021-05-24T04:08:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinteki](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jinteki/32/28358_2.png) [@jinteki](https://community.auth0.com/u/jinteki)\
**Post date:** [May 24, 2021, 4:08am UTC](https://community.auth0.com/t/auth0-nextjs-auth0-calling-me-prior-to-login/63244/1 "2021-05-24T04:08:26Z")

</div>

- **@auth0/nextjs-auth0**
- **1.3.1**
- _next 10.2.2_

The problem that I am having is that my call to login.js is also automatically calling `/api/auth/me`. Given that the user has not logged in yet this call to `/api/auth/me` returns 401 Unauthorised. Which is correct but it seems to me that this call shouldn’t be being made in the first place. I am worried that my setup is not correct.

I was using an earlier version of nextjs-auth0 so I had already created files for login.js, logout.js, callback.js and me.js.

```
// /pages/api/login.js
import auth0 from '../../utils/auth0'

export default async function login(req, res) {
  try {
    await auth0.handleLogin(req, res, {
      returnTo: '/Dashboard'
    })
  } catch (error) {
    console.error(error);
    res.status(error.status || 500).end(error.message);
  }
}

// /utils/auth0.js
import { initAuth0 } from '@auth0/nextjs-auth0'
import getConfig from 'next/config'
const { serverRuntimeConfig } = getConfig()

export default initAuth0({
  baseURL: serverRuntimeConfig.AUTH0_BASE_URL,
  issuerBaseURL: serverRuntimeConfig.AUTH0_ISSUER_BASE_URL,
  clientID: serverRuntimeConfig.AUTH0_CLIENT_ID,
  clientSecret: serverRuntimeConfig.AUTH0_CLIENT_SECRET,
  secret: serverRuntimeConfig.AUTH0_SESSION_COOKIE_SECRET,
  clockTolerance: 60,
  httpTimeout: 5000,
  authorizationParams: {
    scope: 'openid profile email',
    prompt: 'login'
  },
  routes: {
    callback: '/api/callback',
    postLogoutRedirect: serverRuntimeConfig.AUTH0_POST_LOGOUT_REDIRECT_URI
  },
  session: {
    rollingDuration: 60 * 60 * 24,
    absoluteDuration: 60 * 60 * 24 * 7
  }
})

```

Upgrading to v1.3.1 meant that I needed to add the following dynamic API route handler:

```
// /pages/api/auth/[...auth0].js
import auth0 from '../../../utils/auth0'

export default auth0.handleAuth()

```

that creates the following urls: `/api/auth/login` , `/api/auth/callback` , `/api/auth/logout` and `/api/auth/me` .

So to reiterate, it all seems to work, **except** that my call to /api/login (my pre-existing file and not the auto-generated `/api/auth/login`) also causes a call to `/api/auth/me`. This call fails with a 401 as the user hasn’t logged in yet - so no **me** to return. Can I prevent this call to `/api/auth/me`?

Thanks.

---

<div class="post-metadata">

**Author:** ![Vinze](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vinze/32/32034_2.png) [@Vinze](https://community.auth0.com/u/Vinze)\
**Post date:** [September 29, 2021, 11:53pm UTC](https://community.auth0.com/t/auth0-nextjs-auth0-calling-me-prior-to-login/63244/2 "2021-09-29T23:53:00Z")

</div>

Hi,  
I have the same issue with the same setup.  
Did you found out what was the issue by chance?

---

<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:** [October 6, 2021, 11:39am UTC](https://community.auth0.com/t/auth0-nextjs-auth0-calling-me-prior-to-login/63244/3 "2021-10-06T11:39:20Z")

</div>

Hey there!

I think the best way to handle that would be to raise it as a GitHub issue in the repo so we can talk about it directly with the repo maintainers. Thank you!

---

<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 21, 2021, 11:40am UTC](https://community.auth0.com/t/auth0-nextjs-auth0-calling-me-prior-to-login/63244/4 "2021-10-21T11:40:06Z")

</div>

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