Next.js Discord

Discord Forum

Receiving a 405 error trying to use NextAuth

Answered
Russian Blue posted this in #help-forum
Open in Discord
Russian BlueOP
I'm using NextAuth with the Prisma adapter and sqlite. When I visit /api/auth/signin and enter my email, I get sent to /api/auth/email and get a 405 (method not allowed) error.

My /api/auth/[...nextauth]/route.ts looks like this:
import NextAuth from "next-auth"
import EmailProvider from "next-auth/providers/email";
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient();

export const authOptions = {
    adapter: PrismaAdapter(prisma),
    providers: [
        EmailProvider({
            server: {
                host: process.env.EMAIL_SERVER_HOST,
                port: process.env.EMAIL_SERVER_PORT,
                auth: {
                    user: process.env.EMAIL_SERVER_USER,
                    pass: process.env.EMAIL_SERVER_PASSWORD
                }
            },
            from: process.env.EMAIL_FROM
        }),
    ],
}

const handler = NextAuth(authOptions);
export { handler as GET, handler as Post };
Answered by riský
try changing handler as Post to handler as POST
View full answer

5 Replies

try changing handler as Post to handler as POST
Answer
Russian BlueOP
will do
@riský try changing `handler as Post` to `handler as POST`
Russian BlueOP
Oh my god, I've been trying to fix this for three hours.
That was it, sigh. Thanks!
@Russian Blue That was it, sigh. Thanks!
no problem, dont worry i have had similar experiences with simple bugs