Next.js Discord

Discord Forum

Error deployment

Answered
Netherland Dwarf posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by joulev
Page components do not have the callbackUrl prop. If you want to read the query params, use the searchParams prop
View full answer

4 Replies

Original message was deleted
Page components do not have the callbackUrl prop. If you want to read the query params, use the searchParams prop
Answer
@joulev Page components do not have the callbackUrl prop. If you want to read the query params, use the searchParams prop
Netherland Dwarf
okey ty and you have a idea for this?
Failed to compile.
src/app/api/auth/[...nextauth]/route.ts
Type error: Route "src/app/api/auth/[...nextauth]/route.ts" does not match the required types of a Next.js Route.
  "authOptions" is not a valid Route export field.

import { NextAuthOptions } from "next-auth";
import NextAuth from "next-auth/next";
import CredentialsProvider from "next-auth/providers/credentials";
import { connectToDatabase } from "@/helpers/server-helpers";
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcrypt";

export const authOptions: NextAuthOptions = {
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        email: {
          label: "Email",
          type: "email",
          placeholder: "jsmith@mail.com",
        },
        password: {
          label: "Password",
          type: "password",
          placeholder: "******",
        },
      },
      async authorize(credentials) {
        const prisma = new PrismaClient();
        if (!credentials || !credentials.email || !credentials.password)
          return null;

        try {
          await connectToDatabase(prisma);

          const user = await prisma.user.findFirst({
            where: { email: credentials.email },
          });

          if (!user?.password) {
            return null;
          }

          const isPasswordCorrect = await bcrypt.compare(
            credentials.password,
            user.password
          );

          if (isPasswordCorrect) {
            return user as any;
          }

          return null;
        } catch (error) {
          console.log(error);
          return null;
        } finally {
          await prisma.$disconnect();
        }
      },
    }),
  ],
  callbacks: {
    jwt({ token, user }) {
      if (user) token.role = user.role;
      return token;
    },
    session({ session, token }) {
      if (session.user) {
        session.user.role = token.role;
      }
      return session;
    },
  },
  pages: {
    signIn: "/login",
  },
  secret: process.env.NEXTAUTH_SECRET,
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
@Netherland Dwarf okey ty and you have a idea for this? Failed to compile. src/app/api/auth/[...nextauth]/route.ts Type error: Route "src/app/api/auth/[...nextauth]/route.ts" does not match the required types of a Next.js Route. "authOptions" is not a valid Route export field. tsx import { NextAuthOptions } from "next-auth"; import NextAuth from "next-auth/next"; import CredentialsProvider from "next-auth/providers/credentials"; import { connectToDatabase } from "@/helpers/server-helpers"; import { PrismaClient } from "@prisma/client"; import bcrypt from "bcrypt"; export const authOptions: NextAuthOptions = { providers: [ CredentialsProvider({ name: "Credentials", credentials: { email: { label: "Email", type: "email", placeholder: "jsmith@mail.com", }, password: { label: "Password", type: "password", placeholder: "******", }, }, async authorize(credentials) { const prisma = new PrismaClient(); if (!credentials || !credentials.email || !credentials.password) return null; try { await connectToDatabase(prisma); const user = await prisma.user.findFirst({ where: { email: credentials.email }, }); if (!user?.password) { return null; } const isPasswordCorrect = await bcrypt.compare( credentials.password, user.password ); if (isPasswordCorrect) { return user as any; } return null; } catch (error) { console.log(error); return null; } finally { await prisma.$disconnect(); } }, }), ], callbacks: { jwt({ token, user }) { if (user) token.role = user.role; return token; }, session({ session, token }) { if (session.user) { session.user.role = token.role; } return session; }, }, pages: { signIn: "/login", }, secret: process.env.NEXTAUTH_SECRET, }; const handler = NextAuth(authOptions); export { handler as GET, handler as POST };
You cannot export authOptions from that file. Export it from a different file and import the authOptions to this route.ts
Netherland Dwarf
ty