Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route "[...nextauth]/route.ts" does not match the required types of a Next.js Route. Invalid configuration "GET": #10845

Closed
avi312singh opened this issue May 7, 2024 · 3 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@avi312singh
Copy link

avi312singh commented May 7, 2024

Environment

  System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 239.02 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.5.0 - ~/.nvm/versions/node/v21.5.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v21.5.0/bin/npm
  Browsers:
    Chrome: 124.0.6367.119
    Safari: 17.4.1
  npmPackages:
    next: ^14.2.3 => 14.2.3 
    next-auth: ^5.0.0-beta.17 => 5.0.0-beta.17 
    react: 18.3.1 => 18.3.1 

Reproduction URL

https://github.com/avi312NHS/next-auth-issue

Describe the issue

After migrating to next-auth v5 I am getting a build error with my current route.ts configuration

image

How to reproduce

As per reproduction repo cloned from - https://github.com/nextauthjs/next-auth-example, export auth configuration options to another directory and try to npm run build

app/api/auth/[...nextauth]/route.ts

import NextAuth from 'next-auth';
import { authOptions } from '../../../../config/authOptions';

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

config/authOptions.ts

import { NextAuthConfig } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';

let users: any[] = [];

export const authOptions: NextAuthConfig = {
  providers: [
    CredentialsProvider({
      name: 'Credentials',
      credentials: {
        email: { label: 'Email', type: 'text', placeholder: 'Enter Email' },
        password: { label: 'Password', type: 'password' },
      },
      async authorize(credentials, req) {
        if (!credentials || !credentials.email || !credentials.password) {
          return null;
        }
        const user = users.find((item) => item.email === credentials.email);
        if (user?.password === credentials.password) {
          const modifiedUser = {
            ...user,
            accountStatus: 'Active',
          };

          return modifiedUser;
        }
        return null;
      },
    }),
  ],
  pages: {
    signIn: '/signin',
    error: '/autherror',
  },
};

Expected behavior

No TS build failures after migrating from V4 to v5, I cannot see any docs related to the changing of the route exporting format -> Next auth docs
This code was fully functional with:

"next": "^13.5.6",
"next-auth": "^4.24.5"

Other unanswered issues with same error

https://stackoverflow.com/questions/78214384/type-error-route-app-api-auth-nextauth-route-ts-does-not-match-the-requi
https://stackoverflow.com/questions/77637651/authoptions-is-not-a-valid-route-export-field

@avi312singh avi312singh added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels May 7, 2024
@mattixpet
Copy link

Using that last stackoverflow link actually solved the error for me in my app.

@avi312singh
Copy link
Author

Yes likewise

@Minttsaka
Copy link

correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

3 participants