Skip to content

Commit

Permalink
added error handling for logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
cameochoquer committed Aug 2, 2023
1 parent 8b10aa5 commit c370f39
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/app/log-in/components/LogInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function SignInForm() {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [loggedIn, setLoggedIn] = useState(false)
const [newError, setNewError] = useState('')
const supabase = createClientComponentClient<Database>()
const router = useRouter()

Expand Down Expand Up @@ -42,6 +43,17 @@ export default function SignInForm() {
})

if (!errorLoggingIn && session) setLoggedIn(true)
if (errorLoggingIn) {
if (errorLoggingIn.status === 400) {
setNewError(
'Trouble logging in, please check your password and try again',
)
} else {
// Handle other errors (optional)
console.log('Error:', errorLoggingIn.message)
}
return
}

router.refresh()
}
Expand Down Expand Up @@ -79,6 +91,7 @@ export default function SignInForm() {
type="password"
/>
</div>
<span>{newError}</span>
<Button className="self-end" color="purple">
<Link href="/sign-up"> Don&apos;t have an account yet? </Link>
</Button>
Expand Down

0 comments on commit c370f39

Please sign in to comment.