Next.js Discord

Discord Forum

auth.js middleware

Answered
Pyramid ant posted this in #help-forum
Open in Discord
Avatar
Pyramid antOP
Hello, when i created a middleware i got this error:

[auth][error] MissingAdapter: Email login requires an adapter. Read more at https://errors.authjs.dev#missingadapter
    at assertConfig (C:\Users\wvn_0\Desktop\project\my-app\.next\server\edge\chunks\node_modules_@auth_core_d0be13._.js:657:34)
    at Auth (C:\Users\wvn_0\Desktop\project\my-app\.next\server\edge\chunks\node_modules_@auth_core_d0be13._.js:5193:202)



How can i fix it.. I looked at the web nothing was there
Answered by Pyramid ant
but i fixed it somehow... i used this:

auth.ts:

import NextAuth from "next-auth"
import authConfig from "../../auth.config"
 
export const { handlers, signIn, signOut, auth } = NextAuth({
  ...authConfig
})


auth.config.ts:

import Resend from "next-auth/providers/resend"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { prisma } from "./src/utils/db" // Adjust path if needed
import type { NextAuthConfig } from "next-auth"

export default {
  adapter: PrismaAdapter(prisma),
  session: { strategy: "jwt" },
  providers: [
    Resend({
      from: "no-reply@domain.com",
    }),
  ],
  secret: process.env.AUTH_SECRET, // Ensure this is set in your .env file
  pages: {
    signIn: "/signin",
    signOut: "/signout",
    newUser: "/",
  },
} satisfies NextAuthConfig;
View full answer

19 Replies

Avatar
Pyramid antOP
I have adapter
Avatar
show
Avatar
Pyramid antOP
But it dont detect
Avatar
Pyramid antOP
but i fixed it somehow... i used this:

auth.ts:

import NextAuth from "next-auth"
import authConfig from "../../auth.config"
 
export const { handlers, signIn, signOut, auth } = NextAuth({
  ...authConfig
})


auth.config.ts:

import Resend from "next-auth/providers/resend"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { prisma } from "./src/utils/db" // Adjust path if needed
import type { NextAuthConfig } from "next-auth"

export default {
  adapter: PrismaAdapter(prisma),
  session: { strategy: "jwt" },
  providers: [
    Resend({
      from: "no-reply@domain.com",
    }),
  ],
  secret: process.env.AUTH_SECRET, // Ensure this is set in your .env file
  pages: {
    signIn: "/signin",
    signOut: "/signout",
    newUser: "/",
  },
} satisfies NextAuthConfig;
Answer
Avatar
are you sure it connects to prisma?
Avatar
@Diamond Master are you sure it connects to prisma?
Avatar
Pyramid antOP
Its fixed alredy
Avatar
oh
what was the error?
Avatar
ah
idk then
how was the code before that
Avatar
Pyramid antOP
I dont know. I rewrited it alredy
Avatar
ah ok
mark it as a solution
perfect