33 lines
799 B
TypeScript
33 lines
799 B
TypeScript
import { resetPlaybackStores } from "@otunes/convex/client/playback-store"
|
|
import { clearPersistentCache } from "@/lib/persistent-cache"
|
|
|
|
/** Forgets this device's cached library and playback state. */
|
|
export async function clearLocalData() {
|
|
resetPlaybackStores()
|
|
await clearPersistentCache()
|
|
}
|
|
|
|
/** Root route guards leave the app when the session or server is cleared. */
|
|
export async function signOut(invalidateSession: () => Promise<void>) {
|
|
try {
|
|
await invalidateSession()
|
|
} finally {
|
|
await clearLocalData()
|
|
}
|
|
}
|
|
|
|
export async function changeServer(
|
|
invalidateSession: () => Promise<void>,
|
|
clearServer: () => Promise<void>
|
|
) {
|
|
try {
|
|
await invalidateSession()
|
|
} finally {
|
|
try {
|
|
await clearServer()
|
|
} finally {
|
|
await clearLocalData()
|
|
}
|
|
}
|
|
}
|