@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.js
CHANGED
|
@@ -4372,7 +4372,8 @@ async function loginWithRedirect(opts) {
|
|
|
4372
4372
|
// Stash the verifier + state so the redirect_uri page can finish the exchange. sessionStorage
|
|
4373
4373
|
// is per-tab and cleared on close — appropriate for a short-lived auth handshake.
|
|
4374
4374
|
sessionStorage.setItem(PKCE_STORE_KEY, JSON.stringify(pkce));
|
|
4375
|
-
|
|
4375
|
+
setAuthLoading(true); // reflect "signing in…" right up to navigation; the return page's
|
|
4376
|
+
window.location.href = url; // completeLoginFromRedirect() keeps it true until the user resolves.
|
|
4376
4377
|
}
|
|
4377
4378
|
/** UPGRADE the current anonymous (guest) session by linking a SOCIAL/redirect login
|
|
4378
4379
|
* (e.g. Google) — Firebase `linkWithPopup`/redirect parity. Carries the guest's signed
|
|
@@ -4465,51 +4466,57 @@ async function loginWithPopup(opts) {
|
|
|
4465
4466
|
// Use the RESOLVED redirect_uri (buildAuthorize defaulted it to the current page on web),
|
|
4466
4467
|
// not opts.redirectUri which may be undefined.
|
|
4467
4468
|
const expectedOrigin = new URL(pkce.redirectUri).origin;
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
if (!raw)
|
|
4482
|
-
throw new Error('Missing PKCE state');
|
|
4483
|
-
const pkce = JSON.parse(raw);
|
|
4484
|
-
if (d.state !== pkce.state)
|
|
4485
|
-
throw new Error('OAuth state mismatch');
|
|
4486
|
-
const user = await exchangeCode(d.code, pkce.verifier, pkce.redirectUri);
|
|
4487
|
-
sessionStorage.removeItem(PKCE_STORE_KEY);
|
|
4469
|
+
setAuthLoading(true); // reflect "signing in…" while the popup is open
|
|
4470
|
+
try {
|
|
4471
|
+
return await new Promise((resolve, reject) => {
|
|
4472
|
+
let settled = false;
|
|
4473
|
+
let timer;
|
|
4474
|
+
const cleanup = () => { settled = true; clearInterval(timer); window.removeEventListener('message', onMsg); };
|
|
4475
|
+
const onMsg = async (ev) => {
|
|
4476
|
+
if (ev.origin !== expectedOrigin)
|
|
4477
|
+
return; // only trust the redirect_uri origin
|
|
4478
|
+
const d = ev.data;
|
|
4479
|
+
if (!d || d.type !== 'bounded-oidc-code' || typeof d.code !== 'string')
|
|
4480
|
+
return;
|
|
4481
|
+
cleanup();
|
|
4488
4482
|
try {
|
|
4489
|
-
|
|
4483
|
+
const raw = sessionStorage.getItem(PKCE_STORE_KEY);
|
|
4484
|
+
if (!raw)
|
|
4485
|
+
throw new Error('Missing PKCE state');
|
|
4486
|
+
const pkce = JSON.parse(raw);
|
|
4487
|
+
if (d.state !== pkce.state)
|
|
4488
|
+
throw new Error('OAuth state mismatch');
|
|
4489
|
+
const user = await exchangeCode(d.code, pkce.verifier, pkce.redirectUri);
|
|
4490
|
+
sessionStorage.removeItem(PKCE_STORE_KEY);
|
|
4491
|
+
try {
|
|
4492
|
+
popup.close();
|
|
4493
|
+
}
|
|
4494
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
4495
|
+
resolve(user);
|
|
4490
4496
|
}
|
|
4491
|
-
catch (
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4497
|
+
catch (e) {
|
|
4498
|
+
reject(e);
|
|
4499
|
+
}
|
|
4500
|
+
};
|
|
4501
|
+
window.addEventListener('message', onMsg);
|
|
4502
|
+
// The popup posts its code and then closes ITSELF, so a naive "popup.closed -> reject"
|
|
4503
|
+
// races the just-posted message and would report a spurious "Login window closed" on a
|
|
4504
|
+
// SUCCESSFUL login. When we see it closed, wait a beat for that pending message to settle
|
|
4505
|
+
// before declaring the window closed.
|
|
4506
|
+
timer = setInterval(() => {
|
|
4507
|
+
if (popup.closed) {
|
|
4508
|
+
clearInterval(timer);
|
|
4509
|
+
setTimeout(() => { if (!settled) {
|
|
4510
|
+
cleanup();
|
|
4511
|
+
reject(new Error('Login window closed'));
|
|
4512
|
+
} }, 500);
|
|
4513
|
+
}
|
|
4514
|
+
}, 500);
|
|
4515
|
+
});
|
|
4516
|
+
}
|
|
4517
|
+
finally {
|
|
4518
|
+
setAuthLoading(false);
|
|
4519
|
+
}
|
|
4513
4520
|
}
|
|
4514
4521
|
/** Call this on the redirect_uri page when login was opened via loginWithPopup(): posts the
|
|
4515
4522
|
* code back to the opener and closes. (For the redirect variant use completeLoginFromRedirect.) */
|
|
@@ -4801,7 +4808,13 @@ async function signInAnonymously() {
|
|
|
4801
4808
|
coreConfig.authMethod = 'guest';
|
|
4802
4809
|
setAuthProviderInstance(provider);
|
|
4803
4810
|
setStoredAuthMethod('guest');
|
|
4804
|
-
|
|
4811
|
+
setAuthLoading(true); // reflect "signing in…" while the guest keypair session is minted
|
|
4812
|
+
try {
|
|
4813
|
+
return await provider.login();
|
|
4814
|
+
}
|
|
4815
|
+
finally {
|
|
4816
|
+
setAuthLoading(false);
|
|
4817
|
+
}
|
|
4805
4818
|
}
|
|
4806
4819
|
/**
|
|
4807
4820
|
* Log in with Privy as a co-equal route — selectable at runtime alongside
|