fix(front): clean localStorage on user change
- fix issue with selected drive and user logout/login via another user
(was raising a "404 not found")
- normalize all localStorage to "oxi-" prefix
- add a specific frontend/AGENTS.md for frontend part (stop increasing the global AGENTS.md)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import { fetchMe, tryRefresh } from '$lib/api/endpoints/auth';
|
||||
import { drives } from '$lib/stores/drives.svelte';
|
||||
import type { User } from '$lib/api/types';
|
||||
import { ensureActiveUser } from '$lib/utils/localStoragePrefs';
|
||||
|
||||
class SessionStore {
|
||||
user = $state<User | null>(null);
|
||||
@@ -32,7 +33,8 @@ class SessionStore {
|
||||
if (!me && (await tryRefresh())) {
|
||||
me = await fetchMe();
|
||||
}
|
||||
this.user = me;
|
||||
if (me) this.setUser(me);
|
||||
else this.user = null;
|
||||
} catch {
|
||||
this.user = null;
|
||||
}
|
||||
@@ -40,6 +42,19 @@ class SessionStore {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authenticated user AND run per-user localStorage cleanup
|
||||
* (see `$lib/utils/localStoragePrefs::ensureActiveUser`). Direct
|
||||
* `session.user = …` assignments skip the cleanup — always call
|
||||
* `setUser` on login-flow entry points (form login, OIDC exchange,
|
||||
* existing-session probe) so a switch-account flow inside the same
|
||||
* tab observes the wipe.
|
||||
*/
|
||||
setUser(user: User): void {
|
||||
this.user = user;
|
||||
ensureActiveUser(user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-fetch the authenticated user from the server, bypassing the one-shot
|
||||
* `load()` cache. Call after operations that change server-side user state —
|
||||
|
||||
Reference in New Issue
Block a user