31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { supabase } from './supabase'
|
|
|
|
export interface LocalLogoutResult {
|
|
remoteRevocationConfirmed: boolean
|
|
}
|
|
|
|
/**
|
|
* Attempts server-side refresh-token revocation first, then always performs
|
|
* the caller's local secure purge. A network outage must not trap a user in a
|
|
* signed-in device or leave a reusable refresh token in local storage.
|
|
*
|
|
* Only this device's session is revoked (scope 'local'). The auth client's
|
|
* default scope is 'global', which revoked every refresh token of the account
|
|
* and silently signed the user out of their desktops as well.
|
|
*/
|
|
export async function signOutWithLocalFallback(
|
|
purgeLocalSession: () => Promise<void>,
|
|
): Promise<LocalLogoutResult> {
|
|
let remoteRevocationConfirmed = false
|
|
try {
|
|
const { error } = await supabase.auth.signOut({ scope: 'local' })
|
|
remoteRevocationConfirmed = error === null
|
|
} catch {
|
|
remoteRevocationConfirmed = false
|
|
}
|
|
|
|
// This remains fatal: the UI must never claim local logout if Keychain
|
|
// deletion itself failed.
|
|
await purgeLocalSession()
|
|
return { remoteRevocationConfirmed }
|
|
}
|