Next.js Discord

Discord Forum

Google and Github provider's session return "null" in next-auth

Unanswered
Santhosh Prabhakaran posted this in #help-forum
Open in Discord
I'm using next-auth in my NextJS 13 applicaition with prisma. I have set up the auth route in "app/api/auth/[...nextauth]/route.ts" as,

And the signin function looks like,
 const onSubmit = (data: FormData, e: any) => {
    e.preventDefault();

    signIn("credentials", {
      ...data,
      redirect: false,
    }).then((callback) => {
      console.log(callback, "callback");

      if (callback?.error !== "Callback") {
        toast.error("Invalid Credentials!");
      } else {
        toast.success("Logged In!");
        router.refresh();
        return setOpenLoginModal(false);
      }
    });
  };

When I try to login using credentials provider works fine. But with Google and Github, it's returning the session as null without any error. The auth page redirection also comes fine and I can able to select the account properly. But strangely, I'm recieving the session data in my console. I don't know why this is happening. Any help on this would be appreciated.

0 Replies