Spaces:
Running
Running
Pulastya B commited on
Commit ·
ab5e966
1
Parent(s): 27c2ee9
Fix redirect loop: refresh onboarding status after profile save
Browse files
FRRONTEEEND/components/AuthPage.tsx
CHANGED
|
@@ -65,7 +65,7 @@ interface AuthPageProps {
|
|
| 65 |
}
|
| 66 |
|
| 67 |
export const AuthPage: React.FC<AuthPageProps> = ({ onSuccess, onSkip }) => {
|
| 68 |
-
const { signIn, signUp, signInWithGoogle, signInWithGithub, isConfigured, user } = useAuth();
|
| 69 |
const [mode, setMode] = useState<'signin' | 'signup'>('signin');
|
| 70 |
const [currentStep, setCurrentStep] = useState(0);
|
| 71 |
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
@@ -233,6 +233,9 @@ export const AuthPage: React.FC<AuthPageProps> = ({ onSuccess, onSkip }) => {
|
|
| 233 |
|
| 234 |
console.log('Profile saved successfully:', savedProfile);
|
| 235 |
|
|
|
|
|
|
|
|
|
|
| 236 |
// Only proceed if profile was saved successfully
|
| 237 |
setSuccess(isOAuthUser ? 'Profile completed! Redirecting...' : 'Account created successfully! Redirecting...');
|
| 238 |
setTimeout(() => {
|
|
|
|
| 65 |
}
|
| 66 |
|
| 67 |
export const AuthPage: React.FC<AuthPageProps> = ({ onSuccess, onSkip }) => {
|
| 68 |
+
const { signIn, signUp, signInWithGoogle, signInWithGithub, isConfigured, user, refreshOnboardingStatus } = useAuth();
|
| 69 |
const [mode, setMode] = useState<'signin' | 'signup'>('signin');
|
| 70 |
const [currentStep, setCurrentStep] = useState(0);
|
| 71 |
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
|
|
| 233 |
|
| 234 |
console.log('Profile saved successfully:', savedProfile);
|
| 235 |
|
| 236 |
+
// Refresh onboarding status so AuthContext knows the profile is complete
|
| 237 |
+
await refreshOnboardingStatus();
|
| 238 |
+
|
| 239 |
// Only proceed if profile was saved successfully
|
| 240 |
setSuccess(isOAuthUser ? 'Profile completed! Redirecting...' : 'Account created successfully! Redirecting...');
|
| 241 |
setTimeout(() => {
|
FRRONTEEEND/lib/AuthContext.tsx
CHANGED
|
@@ -13,6 +13,7 @@ interface AuthContextType {
|
|
| 13 |
signInWithGoogle: () => Promise<{ error: any }>;
|
| 14 |
signInWithGithub: () => Promise<{ error: any }>;
|
| 15 |
signOut: () => Promise<void>;
|
|
|
|
| 16 |
isAuthenticated: boolean;
|
| 17 |
isConfigured: boolean;
|
| 18 |
}
|
|
@@ -126,6 +127,13 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|
| 126 |
return { error };
|
| 127 |
};
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
const signOut = async () => {
|
| 130 |
try {
|
| 131 |
if (dbSessionId) {
|
|
@@ -156,6 +164,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|
| 156 |
signInWithGoogle,
|
| 157 |
signInWithGithub,
|
| 158 |
signOut,
|
|
|
|
| 159 |
isAuthenticated: !!user,
|
| 160 |
isConfigured: configured
|
| 161 |
}}
|
|
|
|
| 13 |
signInWithGoogle: () => Promise<{ error: any }>;
|
| 14 |
signInWithGithub: () => Promise<{ error: any }>;
|
| 15 |
signOut: () => Promise<void>;
|
| 16 |
+
refreshOnboardingStatus: () => Promise<void>;
|
| 17 |
isAuthenticated: boolean;
|
| 18 |
isConfigured: boolean;
|
| 19 |
}
|
|
|
|
| 127 |
return { error };
|
| 128 |
};
|
| 129 |
|
| 130 |
+
const refreshOnboardingStatus = async () => {
|
| 131 |
+
if (user) {
|
| 132 |
+
const profile = await getUserProfile(user.id);
|
| 133 |
+
setNeedsOnboarding(!profile || !profile.onboarding_completed);
|
| 134 |
+
}
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
const signOut = async () => {
|
| 138 |
try {
|
| 139 |
if (dbSessionId) {
|
|
|
|
| 164 |
signInWithGoogle,
|
| 165 |
signInWithGithub,
|
| 166 |
signOut,
|
| 167 |
+
refreshOnboardingStatus,
|
| 168 |
isAuthenticated: !!user,
|
| 169 |
isConfigured: configured
|
| 170 |
}}
|