mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-01-11 20:10:25 +00:00
app opening glitch fix
This commit is contained in:
parent
999a33f82b
commit
57036aaffb
1 changed files with 6 additions and 18 deletions
|
|
@ -49,32 +49,20 @@ export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
|||
|
||||
// Auth state listener
|
||||
const { data: subscription } = supabase.auth.onAuthStateChange(async (_event, session) => {
|
||||
// Do not block UI on auth transitions
|
||||
setLoading(true);
|
||||
try {
|
||||
const fullUser = session?.user ? await accountService.getCurrentUser() : null;
|
||||
setUser(fullUser);
|
||||
// Immediately clear loading so UI can transition to MainTabs/Auth
|
||||
setLoading(false);
|
||||
if (fullUser) {
|
||||
// Run sync in background without blocking UI
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await syncService.migrateLocalScopeToUser();
|
||||
await new Promise(r => setTimeout(r, 0));
|
||||
await syncService.subscribeRealtime();
|
||||
await new Promise(r => setTimeout(r, 0));
|
||||
await syncService.fullPull();
|
||||
await new Promise(r => setTimeout(r, 0));
|
||||
await syncService.fullPush();
|
||||
} catch (error) {
|
||||
console.warn('[AccountContext] Background sync failed:', error);
|
||||
}
|
||||
}, 0);
|
||||
await syncService.migrateLocalScopeToUser();
|
||||
await syncService.subscribeRealtime();
|
||||
// Pull first to hydrate local state, then push to avoid wiping server with empty local
|
||||
await syncService.fullPull();
|
||||
await syncService.fullPush();
|
||||
} else {
|
||||
syncService.unsubscribeRealtime();
|
||||
}
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue