migrate auth v2 code

This commit is contained in:
JCEEE
2026-08-16 10:11:39 +01:00
parent 3dd94b8a7c
commit c73ced7894
45 changed files with 1965 additions and 1519 deletions
+15 -7
View File
@@ -7,8 +7,18 @@ interface ChatInit {
actorType: 'admin' | 'member';
actorName: string;
actorColor: string;
deviceToken?: string;
memberId?: string;
pbToken?: string;
}
// Client id for optimistic chat messages. `crypto.randomUUID()` requires a
// secure context (HTTPS/localhost) — over plain HTTP on a LAN it's undefined,
// so fall back to a time+random string that's still unique enough per session.
function genClientId(): string {
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
}
return Date.now().toString(36) + Math.random().toString(36).slice(2);
}
class ChatStore {
@@ -23,8 +33,7 @@ class ChatStore {
actorType = $state<'admin' | 'member'>('member');
actorName = $state('');
actorColor = $state('');
deviceToken = $state('');
memberId = $state('');
pbToken = $state('');
private unsubs: (() => void)[] = [];
private destroyed = false;
@@ -46,8 +55,7 @@ class ChatStore {
this.actorType = opts.actorType;
this.actorName = opts.actorName;
this.actorColor = opts.actorColor;
this.deviceToken = opts.deviceToken || '';
this.memberId = opts.memberId || '';
this.pbToken = opts.pbToken || '';
if (this.initialized && this.famId === opts.famId) return;
if (this.initPromise) {
@@ -185,7 +193,7 @@ class ChatStore {
async send(content: string) {
const text = content.trim();
if (!text || !this.famId) return;
const clientId = crypto.randomUUID();
const clientId = genClientId();
const temp: ChatMessage = {
id: 'temp-' + clientId,
famId: this.famId,