Skip to content

Commit 20566e4

Browse files
committed
Fix sign in loading page
1 parent 92d1cac commit 20566e4

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

web/pages/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {ProfilesHome} from "web/components/profiles/profiles-home";
77

88
export default function ProfilesPage() {
99
const user = useUser();
10+
console.log('user:', user)
1011

1112
return (
1213
<LovePage trackPageView={'user profiles'}>

web/pages/signin.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@ import {getLoverRow} from "common/love/lover";
1212
import {db} from "web/lib/supabase/db";
1313
import Router from "next/router";
1414
import {LovePage} from "web/components/love-page";
15-
16-
17-
async function redirectSignin(creds: any) {
18-
console.log("User signed in:", creds.user);
19-
const userId = creds?.user.uid
20-
await Router.push('/')
21-
if (userId) {
22-
try {
23-
const lover = await getLoverRow(userId, db)
24-
if (!lover) {
25-
await Router.push('/signup')
26-
}
27-
} catch (error) {
28-
console.error("Error fetching lover profile:", error);
29-
}
30-
}
31-
}
32-
15+
import {useUser} from "web/hooks/use-user";
3316

3417
export default function LoginPage() {
3518
return (
@@ -44,6 +27,7 @@ function RegisterComponent() {
4427
const [error, setError] = useState<string | null>(null);
4528
const [isLoading, setIsLoading] = useState(false);
4629
const [isLoadingGoogle, setIsLoadingGoogle] = useState(false);
30+
const user = useUser()
4731

4832
useEffect(() => {
4933
const error = searchParams.get('error');
@@ -54,12 +38,32 @@ function RegisterComponent() {
5438
}
5539
}, [searchParams]);
5640

41+
useEffect(() => {
42+
const checkAndRedirect = async () => {
43+
if (user) {
44+
console.log("User signed in:", user);
45+
try {
46+
const lover = await getLoverRow(user.id, db)
47+
if (lover) {
48+
await Router.push('/')
49+
} else {
50+
await Router.push('/signup')
51+
}
52+
} catch (error) {
53+
console.error("Error fetching lover profile:", error);
54+
}
55+
setIsLoading(false);
56+
setIsLoadingGoogle(false);
57+
}
58+
}
59+
checkAndRedirect()
60+
}, [user]);
61+
5762
const handleGoogleSignIn = async () => {
5863
setIsLoadingGoogle(true);
5964
setError(null);
6065
try {
6166
const creds = await firebaseLogin();
62-
await redirectSignin(creds)
6367
} catch (error) {
6468
console.error("Error signing in:", error);
6569
const message = 'Failed to sign in with Google';
@@ -72,7 +76,6 @@ function RegisterComponent() {
7276
const handleEmailPasswordSignIn = async (email: string, password: string) => {
7377
try {
7478
const creds = await signInWithEmailAndPassword(auth, email, password);
75-
await redirectSignin(creds)
7679
} catch (error) {
7780
console.error("Error signing in:", error);
7881
const message = 'Failed to sign in with your email and password';

0 commit comments

Comments
 (0)