Next.js Discord

Discord Forum

API handler warning

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
API handler should not return a value, received object.

anyone know how to fix this, console thing?

17 Replies

return NextResponse object, not values/object
Brown bearOP
this is my current authoptions im returning a user
CredentialsProvider({
      name: "Credentials",
      credentials: {
        email: {
          label: "Email",
          type: "text",
          placeholder: "jsmith@example.com",
        },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        if (!credentials) return null;

        signInWithEmailAndPassword(auth, credentials.email, credentials.password)
          .then(userCredential => userCredential.user)
          .catch(error => {
            console.log(error);
            null;
          });

        return null;
      }
    }),
thats not api handler
Brown bearOP
I dont have a api handler
do i need to define one?
when you setup nextauth you need to create api handler...
so you must have one
either under /pages/api or /app dir
Brown bearOP
The sessionprovider?
or in /app/auth/[...nextauth]/route.ts file
Brown bearOP
in my ...nextauth.js I just have my authoptions with the provider
i dont have the latter file
is it somewhere in the docs?
no you only need one of them
so ure using the one in pages dir
Brown bearOP
yup this is my full file
export const authOptions = {
  // Configure one or more authentication providers
  providers: [
    GoogleProvider({
      clientId: config.google.clientId,
      clientSecret: config.google.clientSecret,
    }),
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        email: {
          label: "Email",
          type: "text",
          placeholder: "jsmith@example.com",
        },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        if (!credentials) return null;

        signInWithEmailAndPassword(auth, credentials.email, credentials.password)
          .then(userCredential => userCredential.user)
          .catch(error => {
            console.log(error);
            null;
          });

        return null;
      }
    }),
  ],
};

export default NextAuth(authOptions);