abckit 0.0.70 → 0.0.72
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.
|
@@ -4,39 +4,26 @@ import {
|
|
|
4
4
|
SECURE_COOKIE_PREFIX,
|
|
5
5
|
stripSecureCookiePrefix
|
|
6
6
|
} from "better-auth/cookies";
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
if (!_PreferencesLoading) {
|
|
15
|
-
_PreferencesLoading = import("@capacitor/preferences").then((mod) => {
|
|
16
|
-
_Preferences = mod.Preferences;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
await _PreferencesLoading;
|
|
20
|
-
}
|
|
21
|
-
function getPreferencesSync() {
|
|
22
|
-
if (!_Preferences) {
|
|
23
|
-
throw new Error("[Capacitor] Preferences not loaded. Call ensurePreferences() first.");
|
|
7
|
+
let _PreferencesMod = null;
|
|
8
|
+
let _BrowserMod = null;
|
|
9
|
+
let _AppMod = null;
|
|
10
|
+
async function getPreferencesMod() {
|
|
11
|
+
if (!_PreferencesMod) {
|
|
12
|
+
_PreferencesMod = await import("@capacitor/preferences");
|
|
24
13
|
}
|
|
25
|
-
return
|
|
14
|
+
return _PreferencesMod;
|
|
26
15
|
}
|
|
27
|
-
async function
|
|
28
|
-
if (!
|
|
29
|
-
|
|
30
|
-
_Browser = mod.Browser;
|
|
16
|
+
async function getBrowserMod() {
|
|
17
|
+
if (!_BrowserMod) {
|
|
18
|
+
_BrowserMod = await import("@capacitor/browser");
|
|
31
19
|
}
|
|
32
|
-
return
|
|
20
|
+
return _BrowserMod;
|
|
33
21
|
}
|
|
34
|
-
async function
|
|
35
|
-
if (!
|
|
36
|
-
|
|
37
|
-
_App = mod.App;
|
|
22
|
+
async function getAppMod() {
|
|
23
|
+
if (!_AppMod) {
|
|
24
|
+
_AppMod = await import("@capacitor/app");
|
|
38
25
|
}
|
|
39
|
-
return
|
|
26
|
+
return _AppMod;
|
|
40
27
|
}
|
|
41
28
|
function isNativePlatform() {
|
|
42
29
|
if (typeof window === "undefined")
|
|
@@ -184,8 +171,7 @@ export function capacitorClient(opts) {
|
|
|
184
171
|
* Get stored cookie string for manual fetch requests
|
|
185
172
|
*/
|
|
186
173
|
getCookie: async () => {
|
|
187
|
-
await
|
|
188
|
-
const Preferences = getPreferencesSync();
|
|
174
|
+
const { Preferences } = await getPreferencesMod();
|
|
189
175
|
const result = await Preferences.get({ key: normalizeCookieName(cookieName) });
|
|
190
176
|
return getCookie(result?.value || "{}");
|
|
191
177
|
},
|
|
@@ -193,8 +179,7 @@ export function capacitorClient(opts) {
|
|
|
193
179
|
* Get cached session data for offline use
|
|
194
180
|
*/
|
|
195
181
|
getCachedSession: async () => {
|
|
196
|
-
await
|
|
197
|
-
const Preferences = getPreferencesSync();
|
|
182
|
+
const { Preferences } = await getPreferencesMod();
|
|
198
183
|
const result = await Preferences.get({ key: normalizeCookieName(localCacheName) });
|
|
199
184
|
if (!result?.value)
|
|
200
185
|
return null;
|
|
@@ -208,8 +193,7 @@ export function capacitorClient(opts) {
|
|
|
208
193
|
* Clear all stored auth data
|
|
209
194
|
*/
|
|
210
195
|
clearStorage: async () => {
|
|
211
|
-
await
|
|
212
|
-
const Preferences = getPreferencesSync();
|
|
196
|
+
const { Preferences } = await getPreferencesMod();
|
|
213
197
|
await Preferences.remove({ key: normalizeCookieName(cookieName) });
|
|
214
198
|
await Preferences.remove({ key: normalizeCookieName(localCacheName) });
|
|
215
199
|
}
|
|
@@ -223,15 +207,16 @@ export function capacitorClient(opts) {
|
|
|
223
207
|
async onSuccess(context) {
|
|
224
208
|
if (!isNativePlatform())
|
|
225
209
|
return;
|
|
226
|
-
await
|
|
227
|
-
const Preferences = getPreferencesSync();
|
|
210
|
+
const { Preferences } = await getPreferencesMod();
|
|
228
211
|
const normalizedCookieName = normalizeCookieName(cookieName);
|
|
229
212
|
const authToken = context.response.headers.get("set-auth-token");
|
|
230
213
|
if (authToken) {
|
|
231
214
|
const prefixStr = Array.isArray(cookiePrefix) ? cookiePrefix[0] : cookiePrefix;
|
|
232
215
|
const prevCookie = (await Preferences.get({ key: normalizedCookieName }))?.value;
|
|
233
|
-
const
|
|
234
|
-
const
|
|
216
|
+
const baseCookieName = `${prefixStr}.session_token`;
|
|
217
|
+
const secureCookieName = `${SECURE_COOKIE_PREFIX}${baseCookieName}`;
|
|
218
|
+
const tokenCookies = `${baseCookieName}=${authToken}, ${secureCookieName}=${authToken}`;
|
|
219
|
+
const newCookie = getSetCookie(tokenCookies, prevCookie ?? void 0);
|
|
235
220
|
if (hasSessionCookieChanged(prevCookie ?? null, newCookie)) {
|
|
236
221
|
await Preferences.set({ key: normalizedCookieName, value: newCookie });
|
|
237
222
|
store?.notify("$sessionSignal");
|
|
@@ -260,7 +245,7 @@ export function capacitorClient(opts) {
|
|
|
260
245
|
});
|
|
261
246
|
}
|
|
262
247
|
if (context.data?.redirect && (context.request.url.toString().includes("/sign-in") || context.request.url.toString().includes("/link-social")) && !context.request?.body?.includes?.("idToken") && scheme) {
|
|
263
|
-
const [Browser, App] = await Promise.all([
|
|
248
|
+
const [{ Browser }, { App }] = await Promise.all([getBrowserMod(), getAppMod()]);
|
|
264
249
|
const callbackURL = JSON.parse(context.request.body)?.callbackURL;
|
|
265
250
|
const signInURL = context.data?.url;
|
|
266
251
|
const storedCookieJson = (await Preferences.get({ key: normalizedCookieName }))?.value;
|
|
@@ -301,8 +286,7 @@ export function capacitorClient(opts) {
|
|
|
301
286
|
return { url, options };
|
|
302
287
|
}
|
|
303
288
|
await initializeManagers();
|
|
304
|
-
await
|
|
305
|
-
const Preferences = getPreferencesSync();
|
|
289
|
+
const { Preferences } = await getPreferencesMod();
|
|
306
290
|
const normalizedCookieName = normalizeCookieName(cookieName);
|
|
307
291
|
const storedCookie = (await Preferences.get({ key: normalizedCookieName }))?.value;
|
|
308
292
|
const cookie = getCookie(storedCookie || "{}");
|