@n-dream/builders-sdk 1.5.0 → 1.6.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.
- package/dist/auth.js +31 -0
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -145,7 +145,17 @@ export function createAuth(env, track = !env) {
|
|
|
145
145
|
}
|
|
146
146
|
if (!res.ok)
|
|
147
147
|
throw new BuildersError(`Builders could not sign out (status ${res.status}). Try again.`, res.status);
|
|
148
|
+
const body = (await res.json().catch(() => null));
|
|
148
149
|
changed(null);
|
|
150
|
+
// A private app (docs/private-apps.md 6, D161): the files that the
|
|
151
|
+
// service worker saved go, and the worker too, so the next person on
|
|
152
|
+
// this device sees only the gate. The app's own localStorage and
|
|
153
|
+
// IndexedDB stay (Q3). Then the page loads again and shows the gate.
|
|
154
|
+
if (body?.private === true) {
|
|
155
|
+
await clearSavedFiles();
|
|
156
|
+
const { location } = get();
|
|
157
|
+
location.assign(`${location.pathname}${location.search}`);
|
|
158
|
+
}
|
|
149
159
|
},
|
|
150
160
|
accountPage() {
|
|
151
161
|
if (isLocal()) {
|
|
@@ -156,4 +166,25 @@ export function createAuth(env, track = !env) {
|
|
|
156
166
|
},
|
|
157
167
|
};
|
|
158
168
|
}
|
|
169
|
+
// The service worker caches and registrations of this origin. A failure
|
|
170
|
+
// does not stop the sign-out: the session has ended already.
|
|
171
|
+
async function clearSavedFiles() {
|
|
172
|
+
const g = globalThis;
|
|
173
|
+
try {
|
|
174
|
+
if (g.caches)
|
|
175
|
+
for (const k of await g.caches.keys())
|
|
176
|
+
await g.caches.delete(k);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
/* no cache storage */
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const regs = (await g.navigator?.serviceWorker?.getRegistrations()) ?? [];
|
|
183
|
+
for (const r of regs)
|
|
184
|
+
await r.unregister();
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
/* no service worker */
|
|
188
|
+
}
|
|
189
|
+
}
|
|
159
190
|
export const auth = createAuth();
|