Saif Haq
Saif Haq

Reputation: 1

Next-auth authorize function's console log not displaying in terminal and browser console

So i signIn in my custom login page but the Credential Provider's authorize function's console statement is nowhere to be found neither in Browser Console and Terminal. Help :(

const onSubmit = async (e) => {
    e.preventDefault();
    try {
      const res = await signIn("credentials", {
        redirect: false,
        email: "hello@gmail.com",
        password: "1234werwer",
        callbackUrl:`${window.location.origin}`       
      });
      console.log("await", res);
      setAlert({ status: "success", message: "Login successfully" });
      setLoginData({ email: "", password: "" });
    } catch (error) {
      console.log({ error });
      setAlert({ status: "error", message: "Something went wrong" });
    }
  };

Here's the route file snippet:


const authOptions = {
  secret: "hehe,
  pages: {
    signIn: "/login",
  },
  providers: [
    CredentialsProvider({
      // The name to display on the sign in form (e.g. 'Sign in with...')
      name: "my-project",
      async authorize(credentials, req) {
        console.log("authorize>>>>>>")
        const user = await fetch("/api/auth/callback", {})
        return {
          id: "2",
          email: credentials?.email,
        };
      },
      credentials: {
        email: {
          label: "email",type: "email",
          placeholder: "jsmith@example.com",
        },
        password: {
          label: "Password",
          type: "password"
        },
      }
    }),
  ],

  callbacks: {
//....
}

I've made a project but it's not working as expected. Can someone point out the issue? I've searched everywhere and no result is found

EDIT: Here's the next.config file:

/** @type {import('next').NextConfig} */ const nextConfig = {};

module.exports = nextConfig;

Upvotes: 0

Views: 504

Answers (1)

Naga Sai
Naga Sai

Reputation: 36

why do you passed callback url when redirection is set to false?

The callbackUrl specifies to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.

You want to handle the response of the signIn function on the same page where you initiated the signIn, so remove the callback URL and keep the redirection flag ( false )... if the issue still exists and try upgrading to node v20 ( NextAuth signIn not triggering authorize method in my Credentials Provider)

Upvotes: 0

Related Questions