Skip to content

Commit 5dada81

Browse files
committed
Code Rabbit fixes
1 parent 1d3ff52 commit 5dada81

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

frontend/src/components/pages/ForgotPasswrdPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export default function ForgotPasswrdPage() {
6666
const { error } = await supabase.auth.resetPasswordForEmail(email, { redirectTo });
6767
if (error) {
6868
console.error('resetPasswordForEmail failed', error);
69+
toast.error(error.message || 'Could not send reset email.');
70+
return;
6971
}
72+
toast.success('Password reset email sent.');
7073
setMailPage(true);
7174
} catch (err) {
7275
console.error('resetPasswordForEmail unexpected error', err);

frontend/src/components/pages/ResetPasswordPage.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ const AuthLayout = ({ children }: AuthLayoutProps) => (
3232
</div>
3333
);
3434

35-
const InputField = ({ icon: Icon, ...props }: InputFieldProps) => (
35+
const InputField = ({ icon: Icon, className, ...props }: InputFieldProps) => (
3636
<div className="relative">
3737
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
3838
<Icon className="h-5 w-5 text-gray-400" />
3939
</div>
4040
<input
41-
{...props}
42-
className="block w-full pl-10 pr-3 py-2 border border-gray-800 rounded-lg bg-gray-900 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"
41+
{...props}
42+
className={`block w-full pl-10 pr-3 py-2 border border-gray-800 rounded-lg bg-gray-900 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent ${className ?? ''}`}
4343
/>
4444
</div>
4545
);
@@ -53,15 +53,16 @@ export default function ResetPasswordPage() {
5353

5454

5555
useEffect(() => {
56-
const params = new URLSearchParams(window.location.hash.slice(1));
56+
const paramsHash = new URLSearchParams(window.location.hash.slice(1));
57+
const paramsSearch = new URLSearchParams(window.location.search);
5758

58-
const accessToken = params.get('access_token');
59-
const refreshToken = params.get('refresh_token');
59+
const accessToken = paramsHash.get('access_token');
60+
const refreshToken = paramsHash.get('refresh_token');
61+
const code = paramsSearch.get('code');
6062

61-
const clearUrlHash = () => {
62-
if (window.location.hash) {
63-
window.history.replaceState({}, document.title, window.location.pathname + window.location.search);
64-
}
63+
const clearUrl = () => {
64+
const url = window.location.pathname;
65+
window.history.replaceState({}, document.title, url);
6566
};
6667

6768
if (accessToken && refreshToken) {
@@ -79,17 +80,33 @@ export default function ResetPasswordPage() {
7980
toast.error("Error setting session");
8081
navigate('/login', { replace: true });
8182
} finally {
82-
clearUrlHash();
83+
clearUrl();
84+
}
85+
})();
86+
} else if (code) {
87+
(async () => {
88+
try {
89+
const { error } = await supabase.auth.exchangeCodeForSession(code);
90+
if (error) {
91+
toast.error("Error exchanging code: " + error.message);
92+
navigate('/login', { replace: true });
93+
}
94+
} catch {
95+
toast.error("Error exchanging code");
96+
navigate('/login', { replace: true });
97+
} finally {
98+
clearUrl();
8399
}
84100
})();
85101
} else {
86102
toast.error("Access denied");
87103
navigate('/login', { replace: true });
88-
clearUrlHash();
104+
clearUrl();
89105
}
90106
}, [navigate]);
91107

92108

109+
93110
const handleAuth = async (e: FormEvent<HTMLFormElement>) => {
94111
e.preventDefault();
95112
const formData = new FormData(e.currentTarget);

frontend/src/components/pages/SignUpPage.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ const AuthLayout = ({ children }: AuthLayoutProps) => (
3535
</div>
3636
);
3737

38-
const InputField = ({ icon: Icon, ...props }: InputFieldProps) => (
38+
const InputField = ({ icon: Icon, className, ...props }: InputFieldProps) => (
3939
<div className="relative">
4040
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
4141
<Icon className="h-5 w-5 text-gray-400" />
4242
</div>
4343
<input
4444
{...props}
45-
className="block w-full pl-10 pr-3 py-2 border border-gray-800 rounded-lg bg-gray-900 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"
45+
className={`block w-full pl-10 pr-3 py-2 border border-gray-800 rounded-lg bg-gray-900 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent ${className ?? ''}`}
4646
/>
4747
</div>
4848
);
@@ -86,27 +86,29 @@ export default function SignUpPage() {
8686
return;
8787
}
8888
setIsLoading(true);
89-
const { data, error } = await supabase.auth.signUp({
90-
email: email,
91-
password: password,
92-
options: {
93-
data: {
94-
display_name: name
89+
try {
90+
const redirectTo = import.meta.env.VITE_BASE_URL || window.location.origin;
91+
const { data, error } = await supabase.auth.signUp({
92+
email,
93+
password,
94+
options: {
95+
data: { display_name: name },
96+
emailRedirectTo: redirectTo,
9597
},
96-
emailRedirectTo: import.meta.env.VITE_BASE_URL,
97-
},
98-
})
99-
setIsLoading(false);
100-
// Email already confirmed
101-
if (data?.user?.confirmed_at) {
102-
toast.error("Email is already registered. Please log in.");
103-
return;
104-
}
105-
if (error) {
106-
toast.error(error.message || "An Unknown error occured!");
107-
return;
98+
});
99+
if (error) {
100+
const msg = /already|exist/i.test(error.message)
101+
? "Email is already registered. Please log in."
102+
: (error.message || "An unknown error occurred!");
103+
toast.error(msg);
104+
return;
105+
}
106+
setMailPage(true);
107+
} catch {
108+
toast.error("Unexpected error during sign up.");
109+
} finally {
110+
setIsLoading(false);
108111
}
109-
setMailPage(true);
110112
};
111113

112114
return (

0 commit comments

Comments
 (0)