1 parent
eaad6f1e77
commit
a5da756803
51 files changed
+537
-672
No files matched your search
@@ -261,12 +261,14 @@ async function refresh(): Promise<Session | null> {
|
||||
try {
|
||||
const data = await gotrue('/token?grant_type=refresh_token', { body: { refresh_token: s.refreshToken } })
|
||||
const next = toSession(data)
|
||||
if (next && next.user.id === s.user.id) setSession(next)
|
||||
// Déconnexion (ou autre compte) pendant le renouvellement : on ne ressuscite pas l'ancienne session
|
||||
if (!next || next.user.id !== s.user.id || current?.user.id !== s.user.id) return null
|
||||
setSession(next)
|
||||
return next
|
||||
} catch (e) {
|
||||
// Jeton de renouvellement refusé (révoqué, compte supprimé…) : on déconnecte
|
||||
const status = (e as { status?: number }).status
|
||||
if (status === 400 || status === 401 || status === 403) setSession(null)
|
||||
if ((status === 400 || status === 401 || status === 403) && current?.user.id === s.user.id) setSession(null)
|
||||
return null
|
||||
} finally {
|
||||
refreshing = null
|
||||
@@ -300,6 +302,7 @@ export async function consumeAuthRedirect(): Promise<{ type?: string; error?: st
|
||||
return { error: code === 'otp_expired' ? t('auth.err.linkExpired') : t('auth.err.linkUsed') }
|
||||
}
|
||||
const accessToken = params.get('access_token') ?? ''
|
||||
if (!TOKEN.test(accessToken)) return { error: t('auth.err.linkInvalid') }
|
||||
try {
|
||||
const user = await gotrue('/user', { method: 'GET', token: accessToken })
|
||||
const s = toSession({
|
||||
@@ -310,6 +313,8 @@ export async function consumeAuthRedirect(): Promise<{ type?: string; error?: st
|
||||
user,
|
||||
})
|
||||
if (!s) return { error: t('auth.err.linkInvalid') }
|
||||
// Un lien ne doit jamais remplacer en douce le compte déjà ouvert sur cet appareil
|
||||
if (current && current.user.id !== s.user.id) return { error: t('auth.err.linkInvalid') }
|
||||
setSession(s)
|
||||
return { type: params.get('type') ?? undefined }
|
||||
} catch (e) {
|
||||
|
||||
+13
-2
@@ -299,15 +299,26 @@ export function createSync(userId: string, hooks: SyncHooks): SyncEngine {
|
||||
}
|
||||
setStatus({ state: 'syncing', error: undefined })
|
||||
try {
|
||||
await push()
|
||||
// Un envoi refusé (fiche trop lourde, quota…) ne doit pas empêcher de recevoir les autres appareils
|
||||
let pushError: unknown
|
||||
try {
|
||||
await push()
|
||||
} catch (e) {
|
||||
pushError = e
|
||||
}
|
||||
// Déconnexion pendant la synchro : on n'écrit plus rien dans la base de cet utilisateur
|
||||
if (stopped) return
|
||||
await pullItems()
|
||||
if (stopped) return
|
||||
await pullLists()
|
||||
if (stopped) return
|
||||
await pullSettings()
|
||||
if (pushError) throw pushError
|
||||
meta.lastSyncAt = new Date().toISOString()
|
||||
saveMeta()
|
||||
setStatus({ state: 'idle', lastSyncAt: meta.lastSyncAt })
|
||||
} catch (e) {
|
||||
setStatus({ state: navigator.onLine ? 'error' : 'offline', error: (e as Error).message })
|
||||
if (!stopped) setStatus({ state: navigator.onLine ? 'error' : 'offline', error: (e as Error).message })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user