0

Hi I was trying do the ecommerce with NextJs, MongoDB and Tailwind CSS. Everyting went right til’ video 15 “Connect to Mongo DB”, in the video 16 “Create login Api”, I followed all steps, but when i click the login button doesn’t send the credentials to the database for their respective validation, i think that ’cause the label Login doesn’t change and redirect neither. I printed result and got this:

{error: null, status: 200, ok: true, url: http://localhost:3000/login’
error: null
ok: true
status: 200
url: http://localhost:3000/login”[[Prototype]]: Object

this is the code

const LoginScreen = () => {
  const { data: session } = useSession();
  const router = useRouter();
  const { redirect } = router.query;
  useEffect(() => {
    if (session?.usuario) {
      router.push(redirect || “/”);
    }
  }, [router, session, redirect]);
  const {
    handleSubmit,
    register,
    formState: { errors },
  } = useForm();
  const submitHandler = async ({ email, password }) => {
    try {
      const result = await signIn(“credentials”, {
        redirect: false,
        email,
        password,
      });
      if (result.error) {
        toast.error(result.error);
      }
    } catch (err) {
      toast.error(getError(err));
    }
  };

Eliam Vazquez Asked question October 26, 2022