@bounded-sh/client 0.0.30 → 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/auth/oidc-auth.d.ts +2 -1
- package/dist/index.js +60 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -37
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +60 -37
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +60 -37
- package/dist/index.native.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.native.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
|
|
@@ -4449,7 +4450,8 @@ async function completeLoginFromRedirect() {
|
|
|
4449
4450
|
}
|
|
4450
4451
|
}
|
|
4451
4452
|
/** Popup variant: open the hosted login in a popup; resolves with the User once the popup's
|
|
4452
|
-
* redirect_uri page posts the code back. The redirect_uri page
|
|
4453
|
+
* redirect_uri page posts the code back. The redirect_uri page just calls the usual
|
|
4454
|
+
* completeLoginFromRedirect() (which auto-detects the popup) — no separate call needed. */
|
|
4453
4455
|
async function loginWithPopup(opts) {
|
|
4454
4456
|
if (!hasDOM())
|
|
4455
4457
|
throw new Error('loginWithPopup is web-only — on React Native use loginWithRedirect()');
|
|
@@ -4464,42 +4466,57 @@ async function loginWithPopup(opts) {
|
|
|
4464
4466
|
// Use the RESOLVED redirect_uri (buildAuthorize defaulted it to the current page on web),
|
|
4465
4467
|
// not opts.redirectUri which may be undefined.
|
|
4466
4468
|
const expectedOrigin = new URL(pkce.redirectUri).origin;
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
const
|
|
4477
|
-
if (!
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
if (d.state !== pkce.state)
|
|
4481
|
-
throw new Error('OAuth state mismatch');
|
|
4482
|
-
const user = await exchangeCode(d.code, pkce.verifier, pkce.redirectUri);
|
|
4483
|
-
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();
|
|
4484
4482
|
try {
|
|
4485
|
-
|
|
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);
|
|
4486
4496
|
}
|
|
4487
|
-
catch (
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
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
|
+
}
|
|
4503
4520
|
}
|
|
4504
4521
|
/** Call this on the redirect_uri page when login was opened via loginWithPopup(): posts the
|
|
4505
4522
|
* code back to the opener and closes. (For the redirect variant use completeLoginFromRedirect.) */
|
|
@@ -4791,7 +4808,13 @@ async function signInAnonymously() {
|
|
|
4791
4808
|
coreConfig.authMethod = 'guest';
|
|
4792
4809
|
setAuthProviderInstance(provider);
|
|
4793
4810
|
setStoredAuthMethod('guest');
|
|
4794
|
-
|
|
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
|
+
}
|
|
4795
4818
|
}
|
|
4796
4819
|
/**
|
|
4797
4820
|
* Log in with Privy as a co-equal route — selectable at runtime alongside
|