brianRingler / time-distance-tracker

https://time-distance-tracker.vercel.app
0 stars 1 forks source link

LoginForm - Bad Login #21

Open brianRingler opened 11 months ago

brianRingler commented 11 months ago

When a user logs into their account and the user email is not found or password is not a match the current code does not properly connect back to the LoginForm.jsx

The below code worked prior to updating the LoginForm to use react-hook-form. When an invalid password or email was provided the throw new error would populate the login page. Need to fix for react-hook-form.

 app/api/auth/[...next-auth]/route.js

          if (userEmail) {
            const isPasswordCorrect = await bcrypt.compare(
              credentials.password,
              userHashedPass
            );

            if (isPasswordCorrect) {
              return user;
            } else {
              console.log("throw new Error => Wrong Credentials Provided");
              throw new Error("Wrong Credentials!");
            }
          } else {
            console.log("throw new Error => User Not Found");
            throw new Error("User not found!");
          }
        } catch (err) {
          console.log(
            `Catch All Errors - route to 'error-page'. Error Msg: ${err}`
          );
          router.push("/error-page");
        }
      },
imaricodes commented 11 months ago

Fix is on imari-handle-login-error branch.