next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

Cannot find [...nextauth].{js,ts} in `/pages/api/auth`

Open Gyurmatag opened this issue 3 years ago • 17 comments

Question 💬

I'm using the app dir, here is my route.js located: app/api/auth/[…nextauth]/route.js And here is the content of the route.js:

import NextAuth from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'
import { PrismaAdapter } from '@next-auth/prisma-adapter'
import { Stripe } from 'stripe'
import prisma from '../../../../prisma/client'
import { STRIPE_API_VERSION } from '@/config'

const adapter = PrismaAdapter(prisma)

export const authOptions = {
  adapter: adapter,
  secret: process.env.AUTH_SECRET,
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    }),
  ],
  pages: {
    signIn: '/sign-in',
  },
  events: {
    createUser: async ({ user }) => {
      const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
        apiVersion: STRIPE_API_VERSION,
      })

      await stripe.customers
        .create({
          email: user.email,
        })
        .then(async (customer) => {
          return prisma.user.update({
            where: { id: user.id },
            data: {
              stripeCustomerId: customer.id,
            },
          })
        })
    },
  },
  callbacks: {
    async session({ session, user }) {
      session.user.id = user.id

      session.user.stripeCustomerId = user.stripeCustomerId
      session.user.stripeSubTier = user.currentSubPlan

      return session
    },
  },
}

const handler = NextAuth(authOptions)
export { handler as GET, handler as POST }

But when I navigate to signIn page I've got this error:

[next-auth][error][MISSING_NEXTAUTH_API_ROUTE_ERROR] 
https://next-auth.js.org/errors#missing_nextauth_api_route_error Cannot find [...nextauth].{js,ts} in `/pages/api/auth`. Make sure the filename is written correctly. MissingAPIRoute [MissingAPIRouteError]: Cannot find [...nextauth].{js,ts} in `/pages/api/auth`. Make sure the filename is written correctly.

What can be the problem here?

Thank you for your help!

How to reproduce ☕️

No reproduction in live environment.

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

Gyurmatag avatar May 23 '23 10:05 Gyurmatag

same issue with credentials provider and typescript nextjs 13.4

majdnaji avatar May 23 '23 10:05 majdnaji

From the issue description, sounds like … needs to be .... Cannot say more without a reproduction.

balazsorban44 avatar May 23 '23 13:05 balazsorban44

Omg. That was the problem. Thank you @balazsorban44! Please consider this dot situation, because it is easy to miss!

Gyurmatag avatar May 23 '23 14:05 Gyurmatag

unfortunately it's not something we can do about in NextAuth.js, it's how Next.js catch-all routes work. We could maybe add a warning though. Will let the Next.js team know. 👍

balazsorban44 avatar May 23 '23 14:05 balazsorban44

worked for me , thanks @balazsorban44

majdnaji avatar May 24 '23 06:05 majdnaji

wow. I'll always copy paste it for now on...

jilherme avatar Jun 08 '23 15:06 jilherme

Faced the same issue. Just check the folder name. It should be named as /[...nextauth]/

aravindame avatar Jun 16 '23 11:06 aravindame

I might have been looking at my code for too long but can someone break this down to me like I'm 5? Do we keep the route.ts file inside the [...nextauth] folder? Should the folder be [. . .nextauth]/route.ts or [. . .nextauth].ts or [...nextauth] etc?

I've tried a few of these options and still get the same error mentioned above.

evanrosa avatar Jun 23 '23 18:06 evanrosa

I was learning how to migrate from /pages to /app from this great guide: https://codevoweb.com/setup-and-use-nextauth-in-nextjs-13-app-directory/#comments @evanrosa I hope that guide can give you more clarity

Just don't copy the "…" character literally out of the line of the guide like I did finding myself here for a fix.

Enalmada avatar Jun 27 '23 20:06 Enalmada

Guys, I apologize for the issue with the three dots. When I initially created the article, I copied the relative path to the route.ts file from VS Code and pasted it directly into the article. Unfortunately, I was unaware that the appearance of the three dots changed unexpectedly during the process.

However, I have now manually typed the three dots in the article, conducted thorough testing, and everything seems to be working correctly. I am confident that no one will encounter the three dots issue again.

wpcodevo avatar Jun 27 '23 21:06 wpcodevo

@wpcodevo I just found myself here as well due to copy / pasting There is a section that still has the ellipses instead of three dots

chrome_3XiqFlGc0l

ContrerasA avatar Jul 04 '23 02:07 ContrerasA

@ContrerasA Thank you for bringing this three dots issue to my attention. I've investigated the matter and noticed that WordPress automatically converts the three dots into ellipses, despite my previous effort to accurately represent them as real three dots by typing them. Nevertheless, I've added a warning note above the URL path, cautioning people to retype the three dots if they choose to copy and paste it.

wpcodevo avatar Jul 04 '23 06:07 wpcodevo

worked mine was Auth instead of auth

mesuhailpm avatar Jul 20 '23 16:07 mesuhailpm

@mesuhailpm Thanks for sharing that. I made the same error and couldn't figure out what the heck I was doing wrong.

ghost avatar Jul 22 '23 15:07 ghost

@balazsorban44 you saved my day ! mv \[…nextauth\] \[...nextauth\] solves the problem, for those who copy/pasted the folder structure from the web

phpepe avatar Aug 21 '23 15:08 phpepe

i also got stuck here as getting the same error as the time i was getting the error the directory was api/auth/[...nextAuth] and i tried everything like making spaces between the dots but it didn't work and then finally i renamed the route as api/auth/[...nextauth]
i dont know the exact reason but worked for me.

raggettii avatar Jul 19 '24 08:07 raggettii

i also got stuck here as getting the same error as the time i was getting the error the directory was api/auth/[...nextAuth] and i tried everything like making spaces between the dots but it didn't work and then finally i renamed the route as api/auth/[...nextauth] i dont know the exact reason but worked for me.

I had the same issue with Auth0. Renamed files api\auth\[auth0]\route.ts to api\auth\[auth0]\route.ts.

badJaguar avatar Oct 04 '24 10:10 badJaguar