Skip to content

Commit b7aebcf

Browse files
committed
Code Rabbit fixes
1 parent 1d3ff52 commit b7aebcf

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
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: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from "react";
2-
import type { ReactNode, FormEvent } from "react";
2+
import type { ReactNode, FormEvent, ComponentPropsWithoutRef, ElementType } from "react";
33
import { motion } from "framer-motion";
44
import { useNavigate } from 'react-router-dom';
55
import { toast} from "react-hot-toast";
@@ -14,11 +14,10 @@ interface AuthLayoutProps {
1414
children: ReactNode;
1515
}
1616

17-
interface InputFieldProps extends React.InputHTMLAttributes<HTMLInputElement> {
18-
icon: React.ElementType;
17+
interface InputFieldProps extends ComponentPropsWithoutRef<'input'> {
18+
icon: ElementType;
1919
}
2020

21-
2221
const AuthLayout = ({ children }: AuthLayoutProps) => (
2322
<div className="min-h-screen bg-gray-950 flex items-center justify-center p-4">
2423
<motion.div
@@ -32,14 +31,14 @@ const AuthLayout = ({ children }: AuthLayoutProps) => (
3231
</div>
3332
);
3433

35-
const InputField = ({ icon: Icon, ...props }: InputFieldProps) => (
34+
const InputField = ({ icon: Icon, className, ...props }: InputFieldProps) => (
3635
<div className="relative">
3736
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
3837
<Icon className="h-5 w-5 text-gray-400" />
3938
</div>
4039
<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"
40+
{...props}
41+
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 ?? ''}`}
4342
/>
4443
</div>
4544
);
@@ -53,15 +52,16 @@ export default function ResetPasswordPage() {
5352

5453

5554
useEffect(() => {
56-
const params = new URLSearchParams(window.location.hash.slice(1));
55+
const paramsHash = new URLSearchParams(window.location.hash.slice(1));
56+
const paramsSearch = new URLSearchParams(window.location.search);
5757

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

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

6767
if (accessToken && refreshToken) {
@@ -79,17 +79,33 @@ export default function ResetPasswordPage() {
7979
toast.error("Error setting session");
8080
navigate('/login', { replace: true });
8181
} finally {
82-
clearUrlHash();
82+
clearUrl();
83+
}
84+
})();
85+
} else if (code) {
86+
(async () => {
87+
try {
88+
const { error } = await supabase.auth.exchangeCodeForSession(code);
89+
if (error) {
90+
toast.error("Error exchanging code: " + error.message);
91+
navigate('/login', { replace: true });
92+
}
93+
} catch {
94+
toast.error("Error exchanging code");
95+
navigate('/login', { replace: true });
96+
} finally {
97+
clearUrl();
8398
}
8499
})();
85100
} else {
86101
toast.error("Access denied");
87102
navigate('/login', { replace: true });
88-
clearUrlHash();
103+
clearUrl();
89104
}
90105
}, [navigate]);
91106

92107

108+
93109
const handleAuth = async (e: FormEvent<HTMLFormElement>) => {
94110
e.preventDefault();
95111
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)