404 on api/auth/[...nextauth].ts
Answered
Brouillard posted this in #help-forum
I'm having a lot of 404 error from my api/auth/... api
I don't understand why.
Here's my [...nextauth].ts file:
I don't understand why.
Here's my [...nextauth].ts file:
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import EmailProvider from "next-auth/providers/email"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import prisma from "../../../utils/prismaClient"
export const authOptions = {
adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {},
async authorize(credentials: any): Promise<any> {
const user = JSON.parse(credentials.user)
},
}),
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: Number(process.env.EMAIL_SERVER_PORT),
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
}),
],
}Answered by riský
ohh wait have you exported your
get and post: https://next-auth.js.org/configuration/initialization#route-handlers-app29 Replies
where did you put that file? (like whats the full path)
app/api/auth/[...nextauth].ts
there was a moment where it worked, I think I have this issue since i'm trying to use the prisma adapter, but not sure
ohh wait have you exported your
get and post: https://next-auth.js.org/configuration/initialization#route-handlers-appAnswer
@Brouillard app/api/auth/[...nextauth].ts
sorry, i didn't read title ;(
@Brouillard app/api/auth/[...nextauth].ts
App router then this is wrong
It has to be app/api/auth/[…nextauth]/route.ts
also didn't see that, good catch
@riský ohh wait have you exported your `get` and `post`: <https://next-auth.js.org/configuration/initialization#route-handlers-app>
And you need to not export authOptions and export GET and POST as per the guide
okay, how comes it worked before ?
i meant that you should follow guide, but yes, don't export authoptions
@Brouillard okay, how comes it worked before ?
Idk. Maybe it was in the pages router? Pages router api routes and app router route handlers follow different conventions and pages/api/auth/[…nextauth].ts is valid
but even then, just exporting authOptions isn't good enough
yeah that was my mistake
replaced authOption with NextAuth and it seems to work better nopw, thanks !
I'm checking before closing the issue
@joulev It has to be app/api/auth/[…nextauth]/**route.ts**
and changed the file name? ^
ectually nop it did/nt change anything
also tried to put it like this [...nextauth]/routes.ts with handler
*route.ts
@Brouillard ectually nop it did/nt change anything
What is the content of app/api/auth/[…nextauth]/route.ts
@Brouillard also tried to put it like this [...nextauth]/routes.ts with handler
Not routes, route. The name is important
The entire path must be app/api/auth/[…nextauth]/route.ts
One wrong character and things blow up
ha yeah sorry trying that
@joulev The entire path must be app/api/auth/[…nextauth]/route.ts
with optional src at start 🙂
okay I still have those rror but now I have more infomation on the "next dev" side :
[next-auth][error][MISSING_ADAPTER_METHODS_ERROR]
https://next-auth.js.org/errors#missing_adapter_methods_error Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail MissingAdapterMethods [MissingAdapterMethodsError]: Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail
at assertConfig (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/lib/assert.js:71:20)
at AuthHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/index.js:90:54)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthRouteHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:50:30)
at async NextAuth._args$ (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:85:24)
at async /home/brouillard/Documents/PROG/rencontres_artistiques/node_modules/.pnpm/next@13.5.5_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:62499 {
code: 'MISSING_ADAPTER_METHODS_ERROR'
}@Brouillard okay I still have those rror but now I have more infomation on the "next dev" side :
[next-auth][error][MISSING_ADAPTER_METHODS_ERROR]
https://next-auth.js.org/errors#missing_adapter_methods_error Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail MissingAdapterMethods [MissingAdapterMethodsError]: Required adapter methods were missing: createVerificationToken, useVerificationToken, getUserByEmail
at assertConfig (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/lib/assert.js:71:20)
at AuthHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/index.js:90:54)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthRouteHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:50:30)
at async NextAuth._args$ (webpack-internal:///(rsc)/./node_modules/.pnpm/next-auth@4.24.3_next@13.5.5_nodemailer@6.9.7_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:85:24)
at async /home/brouillard/Documents/PROG/rencontres_artistiques/node_modules/.pnpm/next@13.5.5_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:62499 {
code: 'MISSING_ADAPTER_METHODS_ERROR'
}
Well this is a next auth specific issue now and a different issue, so
1. Please make a new post with the content of route.ts
2. I haven’t used next-auth in ages so can’t help with this sry
3. There is a link in the error message, check it out
1. Please make a new post with the content of route.ts
2. I haven’t used next-auth in ages so can’t help with this sry
3. There is a link in the error message, check it out
thanks guys i'll do that