Skip to content

Commit fedc4eb

Browse files
fix: implement more robust error handling to get rid of 'any' usage
1 parent c817daf commit fedc4eb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/app/login/page.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ export default function AuthPage() {
2525
if (error) throw error;
2626
} else {
2727
const { error } = await supabase.auth.signUp({ email, password });
28-
if (error) throw error;
28+
if (error) throw error;
2929
}
3030
router.push("/dashboard");
31-
} catch (e: any) {
32-
setErr(e?.message ?? "Something went wrong");
31+
} catch (e: unknown) {
32+
let errorMessage = "Something went wrong. Please try again";
33+
34+
if (e instanceof Error) {
35+
errorMessage = e.message;
36+
} else if (typeof e === "string") {
37+
errorMessage = e;
38+
}
39+
setErr(errorMessage);
3340
} finally {
3441
setBusy(false);
3542
}
@@ -55,14 +62,12 @@ export default function AuthPage() {
5562
>
5663
Sign up
5764
</button>
58-
</div>
65+
</div>
5966

6067
{/* Optional info for signup */}
6168
{mode === "signup" && (
6269
<div role="alert" className="alert alert-soft mb-2">
63-
<span>
64-
Create an account with email & password.
65-
</span>
70+
<span>Create an account with email & password.</span>
6671
</div>
6772
)}
6873

0 commit comments

Comments
 (0)