mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 17:31:12 -05:00
Fix password state sync for OAuth users
This commit is contained in:
@@ -160,6 +160,29 @@ export async function connectIdentity(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for email provider to be created after password addition
|
||||
* Supabase takes time to create the email identity, so we poll with retries
|
||||
*/
|
||||
async function waitForEmailProvider(maxRetries = 4): Promise<boolean> {
|
||||
const delays = [500, 1000, 1500, 2000]; // Exponential backoff
|
||||
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
const identities = await getUserIdentities();
|
||||
const hasEmail = identities.some(id => id.provider === 'email');
|
||||
|
||||
if (hasEmail) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i < maxRetries - 1) {
|
||||
await new Promise(resolve => setTimeout(resolve, delays[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add password authentication to an OAuth-only account
|
||||
*/
|
||||
@@ -180,6 +203,19 @@ export async function addPasswordToAccount(
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// Force session refresh to sync identity state
|
||||
const { error: refreshError } = await supabase.auth.refreshSession();
|
||||
if (refreshError) {
|
||||
console.warn('[IdentityService] Session refresh failed:', refreshError);
|
||||
}
|
||||
|
||||
// Wait for email provider to be created
|
||||
const emailCreated = await waitForEmailProvider();
|
||||
|
||||
if (!emailCreated) {
|
||||
console.warn('[IdentityService] Email provider not found after password addition');
|
||||
}
|
||||
|
||||
// Log audit event
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
if (user) {
|
||||
|
||||
Reference in New Issue
Block a user