Next.js Discord

Discord Forum

API handler warning

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

anyone know how to fix this, console thing?

17 Replies

Avatar
Alfonsus Ardani
return NextResponse object, not values/object
Avatar
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;
      }
    }),
Avatar
Alfonsus Ardani
thats not api handler
Avatar
Brown bearOP
I dont have a api handler
do i need to define one?
Avatar
Alfonsus Ardani
when you setup nextauth you need to create api handler...
so you must have one
either under /pages/api or /app dir
Avatar
Brown bearOP
The sessionprovider?
Avatar
Alfonsus Ardani
Image
or in /app/auth/[...nextauth]/route.ts file
Avatar
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?
Avatar
Alfonsus Ardani
no you only need one of them
so ure using the one in pages dir
Avatar
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);