@bounded-sh/client 0.0.31 → 0.0.32
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/index.js +58 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -45
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +58 -45
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +58 -45
- package/dist/index.native.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.native.mjs
CHANGED
|
@@ -4352,7 +4352,8 @@ async function loginWithRedirect(opts) {
|
|
|
4352
4352
|
// Stash the verifier + state so the redirect_uri page can finish the exchange. sessionStorage
|
|
4353
4353
|
// is per-tab and cleared on close — appropriate for a short-lived auth handshake.
|
|
4354
4354
|
sessionStorage.setItem(PKCE_STORE_KEY, JSON.stringify(pkce));
|
|
4355
|
-
|
|
4355
|
+
setAuthLoading(true); // reflect "signing in…" right up to navigation; the return page's
|
|
4356
|
+
window.location.href = url; // completeLoginFromRedirect() keeps it true until the user resolves.
|
|
4356
4357
|
}
|
|
4357
4358
|
/** UPGRADE the current anonymous (guest) session by linking a SOCIAL/redirect login
|
|
4358
4359
|
* (e.g. Google) — Firebase `linkWithPopup`/redirect parity. Carries the guest's signed
|
|
@@ -4445,51 +4446,57 @@ async function loginWithPopup(opts) {
|
|
|
4445
4446
|
// Use the RESOLVED redirect_uri (buildAuthorize defaulted it to the current page on web),
|
|
4446
4447
|
// not opts.redirectUri which may be undefined.
|
|
4447
4448
|
const expectedOrigin = new URL(pkce.redirectUri).origin;
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
if (!raw)
|
|
4462
|
-
throw new Error('Missing PKCE state');
|
|
4463
|
-
const pkce = JSON.parse(raw);
|
|
4464
|
-
if (d.state !== pkce.state)
|
|
4465
|
-
throw new Error('OAuth state mismatch');
|
|
4466
|
-
const user = await exchangeCode(d.code, pkce.verifier, pkce.redirectUri);
|
|
4467
|
-
sessionStorage.removeItem(PKCE_STORE_KEY);
|
|
4449
|
+
setAuthLoading(true); // reflect "signing in…" while the popup is open
|
|
4450
|
+
try {
|
|
4451
|
+
return await new Promise((resolve, reject) => {
|
|
4452
|
+
let settled = false;
|
|
4453
|
+
let timer;
|
|
4454
|
+
const cleanup = () => { settled = true; clearInterval(timer); window.removeEventListener('message', onMsg); };
|
|
4455
|
+
const onMsg = async (ev) => {
|
|
4456
|
+
if (ev.origin !== expectedOrigin)
|
|
4457
|
+
return; // only trust the redirect_uri origin
|
|
4458
|
+
const d = ev.data;
|
|
4459
|
+
if (!d || d.type !== 'bounded-oidc-code' || typeof d.code !== 'string')
|
|
4460
|
+
return;
|
|
4461
|
+
cleanup();
|
|
4468
4462
|
try {
|
|
4469
|
-
|
|
4463
|
+
const raw = sessionStorage.getItem(PKCE_STORE_KEY);
|
|
4464
|
+
if (!raw)
|
|
4465
|
+
throw new Error('Missing PKCE state');
|
|
4466
|
+
const pkce = JSON.parse(raw);
|
|
4467
|
+
if (d.state !== pkce.state)
|
|
4468
|
+
throw new Error('OAuth state mismatch');
|
|
4469
|
+
const user = await exchangeCode(d.code, pkce.verifier, pkce.redirectUri);
|
|
4470
|
+
sessionStorage.removeItem(PKCE_STORE_KEY);
|
|
4471
|
+
try {
|
|
4472
|
+
popup.close();
|
|
4473
|
+
}
|
|
4474
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
4475
|
+
resolve(user);
|
|
4470
4476
|
}
|
|
4471
|
-
catch (
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4477
|
+
catch (e) {
|
|
4478
|
+
reject(e);
|
|
4479
|
+
}
|
|
4480
|
+
};
|
|
4481
|
+
window.addEventListener('message', onMsg);
|
|
4482
|
+
// The popup posts its code and then closes ITSELF, so a naive "popup.closed -> reject"
|
|
4483
|
+
// races the just-posted message and would report a spurious "Login window closed" on a
|
|
4484
|
+
// SUCCESSFUL login. When we see it closed, wait a beat for that pending message to settle
|
|
4485
|
+
// before declaring the window closed.
|
|
4486
|
+
timer = setInterval(() => {
|
|
4487
|
+
if (popup.closed) {
|
|
4488
|
+
clearInterval(timer);
|
|
4489
|
+
setTimeout(() => { if (!settled) {
|
|
4490
|
+
cleanup();
|
|
4491
|
+
reject(new Error('Login window closed'));
|
|
4492
|
+
} }, 500);
|
|
4493
|
+
}
|
|
4494
|
+
}, 500);
|
|
4495
|
+
});
|
|
4496
|
+
}
|
|
4497
|
+
finally {
|
|
4498
|
+
setAuthLoading(false);
|
|
4499
|
+
}
|
|
4493
4500
|
}
|
|
4494
4501
|
/** Call this on the redirect_uri page when login was opened via loginWithPopup(): posts the
|
|
4495
4502
|
* code back to the opener and closes. (For the redirect variant use completeLoginFromRedirect.) */
|
|
@@ -4781,7 +4788,13 @@ async function signInAnonymously() {
|
|
|
4781
4788
|
coreConfig.authMethod = 'guest';
|
|
4782
4789
|
setAuthProviderInstance(provider);
|
|
4783
4790
|
setStoredAuthMethod('guest');
|
|
4784
|
-
|
|
4791
|
+
setAuthLoading(true); // reflect "signing in…" while the guest keypair session is minted
|
|
4792
|
+
try {
|
|
4793
|
+
return await provider.login();
|
|
4794
|
+
}
|
|
4795
|
+
finally {
|
|
4796
|
+
setAuthLoading(false);
|
|
4797
|
+
}
|
|
4785
4798
|
}
|
|
4786
4799
|
/**
|
|
4787
4800
|
* Log in with Privy as a co-equal route — selectable at runtime alongside
|