fix(app): a re-read of the same account keeps its workspace on screen
USER_UPDATED (or a retry) set the workspace back to loading, which unmounted the client routes and lost an open form's typed values. A ready workspace now stays until the answer; found by the V1-1.5 security audit.
This commit is contained in:
1 parent
ae0bd3f8d8
commit
e1c1980949
2 files changed
+22
-3
No files matched your search
@@ -116,10 +116,13 @@ async function loadWorkspace(
|
||||
user: User,
|
||||
profile: Profile | null,
|
||||
set: Set,
|
||||
get: Get,
|
||||
) {
|
||||
if (!user.email_confirmed_at) return set({ workspace: { status: 'unconfirmed' } })
|
||||
if (profile && !profile.active) return set({ workspace: { status: 'inactive' } })
|
||||
set({ workspace: { status: 'loading' } })
|
||||
// A re-read (USER_UPDATED, retry) keeps a ready workspace on screen until the
|
||||
// answer, so the routes under it, an open form included, stay mounted.
|
||||
if (get().workspace.status !== 'ready') set({ workspace: { status: 'loading' } })
|
||||
try {
|
||||
const id = await fetchPersonalWorkspaceId(client, user.id)
|
||||
set({ workspace: id ? { status: 'ready', id } : { status: 'missing' } })
|
||||
@@ -136,7 +139,7 @@ async function loadAccount(client: FaunosteoClient, user: User, set: Set, get: G
|
||||
])
|
||||
setOwn({ profile, roles })
|
||||
await Promise.all([
|
||||
loadWorkspace(client, user, profile, setOwn),
|
||||
loadWorkspace(client, user, profile, setOwn, get),
|
||||
syncAvatar(client, user, setOwn, get).catch(() => setOwn({ avatar: null })),
|
||||
])
|
||||
}
|
||||
@@ -242,7 +245,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
|
||||
refreshWorkspace: async () => {
|
||||
const user = requireUser(get().user)
|
||||
await loadWorkspace(requireClient(), user, get().profile, setForUser(user, set, get))
|
||||
await loadWorkspace(requireClient(), user, get().profile, setForUser(user, set, get), get)
|
||||
},
|
||||
|
||||
refreshAvatar: async () => {
|
||||
|
||||
Reference in new issue
Block a user