feat(app): personal workspace in the account store, reset on account change
The store reads the personal workspace with the account (ready, loading, inactive, unconfirmed, missing, error; never created in the browser). A change of account drops profile, roles, avatar and workspace at once, and a late answer for the previous account is ignored. generateUuid gives v4 ids on the plain-HTTP LAN origin, where crypto.randomUUID is missing.
This commit is contained in:
1 parent
a0e069959b
commit
ff028ec071
4 files changed
+289
-19
No files matched your search
@@ -11,3 +11,18 @@ export function generateId(): string {
|
||||
}
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* A random version 4 uuid, also on an origin that is not a secure context
|
||||
* (the DEV origin is plain HTTP on the LAN, where crypto.randomUUID is
|
||||
* missing but crypto.getRandomValues is not). Used for request ids the
|
||||
* database stores as uuid.
|
||||
*/
|
||||
export function generateUuid(): string {
|
||||
if (typeof crypto.randomUUID === 'function') return crypto.randomUUID()
|
||||
const bytes = crypto.getRandomValues(new Uint8Array(16))
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')
|
||||
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
|
||||
}
|
||||
Reference in new issue
Block a user