Next JS Auth Error: This action with HTTP GET is not supported by NextAuth.js
Answered
Sun bear posted this in #help-forum
Sun bearOP
This is my folder structure /api/auth/[...nextauth]/route.ts , I am using Next auth here copied from official doc, still getting this error.
This is the codesandbox link -- https://codesandbox.io/p/devbox/dreamy-christian-fxt54c. pls look at this code , if anybody could help.
This is the codesandbox link -- https://codesandbox.io/p/devbox/dreamy-christian-fxt54c. pls look at this code , if anybody could help.
Answered by B33fb0n3
it looks like your import is a bit misspelled. If you remove this the page loads fine 👍
17 Replies
Sun bearOP
import NextAuth from "next-auth"; // or "next-auth/react" if using custom providers
import { NextAuthOptions } from "next-auth";
import Credentials from "next-auth/providers/credentials";
export const authOptions: NextAuthOptions = {
providers: [
Credentials({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text" },
password: { label: "Password", type: "password" },
},
async authorize(credentials): Promise<any> {
console.log(credentials);
// Your logic to verify user credentials
const user = { id: 1, name: "John Doe", email: "john@example.com" };
return user;
},
}),
],
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
import { NextAuthOptions } from "next-auth";
import Credentials from "next-auth/providers/credentials";
export const authOptions: NextAuthOptions = {
providers: [
Credentials({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text" },
password: { label: "Password", type: "password" },
},
async authorize(credentials): Promise<any> {
console.log(credentials);
// Your logic to verify user credentials
const user = { id: 1, name: "John Doe", email: "john@example.com" };
return user;
},
}),
],
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
I am using this code , now page is not loading
entering this url http://localhost:3000/api/auth/ss in the browser
@Sun bear entering this url http://localhost:3000/api/auth/ss in the browser
don't navigate directly to your auth routes. Instead use the functions from next-auth for it. For example like "signIn" to sign in. Or directly a supported endpoint like
/api/auth/signinSun bearOP
can you pls edit that codesandbox and then i will look at it as that will be more helpful
It worked , thanks a lot
@B33fb0n3
happy to help
Sun bearOP
so the thing is that even catching all the routes with [...nextauth], Next Auth will not return you the signin page with any routes
and will throw you an error if it do not recognize the route...is this the exact case ?
As you just copy pasted everything in many imports are messed up and you have multiple duplicate imports. You might want to read thought the docs of next-auth and understand what you are doing: https://next-auth.js.org/getting-started/example
Sun bearOP
Yes thanks a lot , i will go through the docs again
sure thing. Feel free to ask follow up questions in another thread 👍
PS for your future threads: the codesandbox thing is very good! Kindly add some more information on your initial question
PS for your future threads: the codesandbox thing is very good! Kindly add some more information on your initial question
Cape lion
hallo
i facing a problem
you can help me