@sveltebase/auth 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.svelte.d.ts","sourceRoot":"","sources":["../../src/client/auth.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.svelte.d.ts","sourceRoot":"","sources":["../../src/client/auth.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;CAC9B;AAYD,qBAAa,eAAe,CAAC,IAAI,SAAS;IAAE,EAAE,EAAE,GAAG,CAAA;CAAE;;gBAMvC,MAAM,CAAC,EAAE,gBAAgB;IAIrC;;OAEG;IACH,IAAI,IAAI,IAAI,IAAI,GAAG,IAAI,CAMtB;IAED;;OAEG;IACH,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,EAE1B;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;IAiCnC;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC;IA4BnC;;OAEG;IACG,MAAM;CAWb;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,SAAS;IAAE,EAAE,EAAE,GAAG,CAAA;CAAE,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,CAErG"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { liveQuery } from "dexie";
|
|
1
2
|
async function clearSyncData(sync) {
|
|
2
|
-
if (sync
|
|
3
|
+
if (sync && typeof sync.tables !== "undefined") {
|
|
3
4
|
try {
|
|
4
|
-
await Promise.all(sync.
|
|
5
|
+
await Promise.all(sync.tables.map((table) => table.clear()));
|
|
5
6
|
}
|
|
6
7
|
catch (err) {
|
|
7
8
|
console.error("Failed to clear local database tables", err);
|
|
@@ -12,7 +13,7 @@ export class AuthClientState {
|
|
|
12
13
|
#userGetter = $state(null);
|
|
13
14
|
#localOverride = $state(undefined);
|
|
14
15
|
#syncClient;
|
|
15
|
-
#
|
|
16
|
+
#usersSubscription;
|
|
16
17
|
constructor(config) {
|
|
17
18
|
this.#syncClient = config?.syncClient;
|
|
18
19
|
}
|
|
@@ -55,18 +56,12 @@ export class AuthClientState {
|
|
|
55
56
|
this.#localOverride = undefined;
|
|
56
57
|
});
|
|
57
58
|
// Set up the internal sync channel subscription if syncClient is provided and not already initialized.
|
|
58
|
-
|
|
59
|
-
if (this.#syncClient && !this.#usersQuery) {
|
|
59
|
+
if (this.#syncClient && !this.#usersSubscription) {
|
|
60
60
|
const sync = this.#syncClient;
|
|
61
|
-
|
|
62
|
-
this.#
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// Read the user reactively so Svelte tracks this effect dependency
|
|
66
|
-
const activeUser = this.user;
|
|
67
|
-
const query = this.#usersQuery;
|
|
68
|
-
if (query && query.status === "error") {
|
|
69
|
-
console.warn("WebSocket session verification failed: logging out.");
|
|
61
|
+
const observable = liveQuery(() => sync.table("users").toArray());
|
|
62
|
+
this.#usersSubscription = observable.subscribe({
|
|
63
|
+
error: (err) => {
|
|
64
|
+
console.warn("WebSocket session verification failed: logging out.", err);
|
|
70
65
|
this.#localOverride = null;
|
|
71
66
|
fetch("/api/auth/logout", { method: "POST" }).catch(() => {
|
|
72
67
|
// Ignore fetch errors if offline or route not mounted
|
|
@@ -85,10 +80,10 @@ export class AuthClientState {
|
|
|
85
80
|
return;
|
|
86
81
|
const updatedUser = { ...activeUser, ...changes };
|
|
87
82
|
this.#localOverride = updatedUser;
|
|
88
|
-
// 1. Update over Sync WebSocket
|
|
83
|
+
// 1. Update over Sync WebSocket using raw Dexie put
|
|
89
84
|
if (this.#syncClient) {
|
|
90
85
|
try {
|
|
91
|
-
await this.#syncClient.table("users").put(
|
|
86
|
+
await this.#syncClient.table("users").put(updatedUser);
|
|
92
87
|
}
|
|
93
88
|
catch (err) {
|
|
94
89
|
console.error("Failed to update user profile over Sync WebSocket:", err);
|