@nauth-toolkit/client 0.1.82 → 0.1.84
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.cjs +86 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.mjs +86 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -568,6 +568,7 @@ var FetchAdapter = class {
|
|
|
568
568
|
};
|
|
569
569
|
|
|
570
570
|
// src/core/challenge-router.ts
|
|
571
|
+
var OAUTH_STATE_KEY = "nauth_oauth_state";
|
|
571
572
|
var ChallengeRouter = class {
|
|
572
573
|
constructor(config) {
|
|
573
574
|
this.config = config;
|
|
@@ -586,7 +587,8 @@ var ChallengeRouter = class {
|
|
|
586
587
|
if (response.challengeName) {
|
|
587
588
|
await this.navigateToChallenge(response);
|
|
588
589
|
} else {
|
|
589
|
-
await this.
|
|
590
|
+
const queryParams = await this.getStoredOauthState();
|
|
591
|
+
await this.navigateToSuccess(queryParams);
|
|
590
592
|
}
|
|
591
593
|
}
|
|
592
594
|
/**
|
|
@@ -600,11 +602,44 @@ var ChallengeRouter = class {
|
|
|
600
602
|
}
|
|
601
603
|
/**
|
|
602
604
|
* Navigate to success URL.
|
|
605
|
+
*
|
|
606
|
+
* @param queryParams - Optional query parameters to append to the success URL
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* await router.navigateToSuccess({ appState: 'invite-code-123' });
|
|
611
|
+
* ```
|
|
603
612
|
*/
|
|
604
|
-
async navigateToSuccess() {
|
|
605
|
-
|
|
613
|
+
async navigateToSuccess(queryParams) {
|
|
614
|
+
let url = this.config.redirects?.success || "/";
|
|
615
|
+
if (queryParams && Object.keys(queryParams).length > 0) {
|
|
616
|
+
const searchParams = new URLSearchParams();
|
|
617
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
618
|
+
if (value) {
|
|
619
|
+
searchParams.set(key, value);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
const queryString = searchParams.toString();
|
|
623
|
+
url = queryString ? `${url}${url.includes("?") ? "&" : "?"}${queryString}` : url;
|
|
624
|
+
}
|
|
606
625
|
await this.navigate(url);
|
|
607
626
|
}
|
|
627
|
+
/**
|
|
628
|
+
* Retrieve stored OAuth appState from storage.
|
|
629
|
+
*
|
|
630
|
+
* @returns Query params object with appState if present, undefined otherwise
|
|
631
|
+
*/
|
|
632
|
+
async getStoredOauthState() {
|
|
633
|
+
try {
|
|
634
|
+
const stored = await this.config.storage.getItem(OAUTH_STATE_KEY);
|
|
635
|
+
if (stored) {
|
|
636
|
+
await this.config.storage.removeItem(OAUTH_STATE_KEY);
|
|
637
|
+
return { appState: stored };
|
|
638
|
+
}
|
|
639
|
+
} catch {
|
|
640
|
+
}
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
608
643
|
/**
|
|
609
644
|
* Navigate to error URL.
|
|
610
645
|
*
|
|
@@ -719,6 +754,7 @@ var ChallengeRouter = class {
|
|
|
719
754
|
// src/core/client.ts
|
|
720
755
|
var USER_KEY2 = "nauth_user";
|
|
721
756
|
var CHALLENGE_KEY2 = "nauth_challenge_session";
|
|
757
|
+
var OAUTH_STATE_KEY2 = "nauth_oauth_state";
|
|
722
758
|
var hasWindow = () => typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined";
|
|
723
759
|
var defaultStorage = () => {
|
|
724
760
|
if (hasWindow() && typeof window.localStorage !== "undefined") {
|
|
@@ -1622,6 +1658,53 @@ var NAuthClient = class {
|
|
|
1622
1658
|
getChallengeRouter() {
|
|
1623
1659
|
return this.challengeRouter;
|
|
1624
1660
|
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Store OAuth appState from social redirect callback.
|
|
1663
|
+
*
|
|
1664
|
+
* This is called automatically by the social redirect callback guard
|
|
1665
|
+
* when appState is present in the callback URL. The stored state can
|
|
1666
|
+
* be retrieved using getLastOauthState().
|
|
1667
|
+
*
|
|
1668
|
+
* @param appState - OAuth appState value from callback URL
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```typescript
|
|
1672
|
+
* await client.storeOauthState('invite-code-123');
|
|
1673
|
+
* ```
|
|
1674
|
+
*/
|
|
1675
|
+
async storeOauthState(appState) {
|
|
1676
|
+
if (appState && appState.trim() !== "") {
|
|
1677
|
+
await this.config.storage.setItem(OAUTH_STATE_KEY2, appState);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* Get the last OAuth appState from social redirect callback.
|
|
1682
|
+
*
|
|
1683
|
+
* Returns the appState that was stored during the most recent social
|
|
1684
|
+
* login redirect callback. This is useful for restoring UI state,
|
|
1685
|
+
* applying invite codes, or tracking referral information.
|
|
1686
|
+
*
|
|
1687
|
+
* The state is automatically cleared after retrieval to prevent reuse.
|
|
1688
|
+
*
|
|
1689
|
+
* @returns The stored appState, or null if none exists
|
|
1690
|
+
*
|
|
1691
|
+
* @example
|
|
1692
|
+
* ```typescript
|
|
1693
|
+
* const appState = await client.getLastOauthState();
|
|
1694
|
+
* if (appState) {
|
|
1695
|
+
* // Apply invite code or restore UI state
|
|
1696
|
+
* console.log('OAuth state:', appState);
|
|
1697
|
+
* }
|
|
1698
|
+
* ```
|
|
1699
|
+
*/
|
|
1700
|
+
async getLastOauthState() {
|
|
1701
|
+
const stored = await this.config.storage.getItem(OAUTH_STATE_KEY2);
|
|
1702
|
+
if (stored) {
|
|
1703
|
+
await this.config.storage.removeItem(OAUTH_STATE_KEY2);
|
|
1704
|
+
return stored;
|
|
1705
|
+
}
|
|
1706
|
+
return null;
|
|
1707
|
+
}
|
|
1625
1708
|
};
|
|
1626
1709
|
|
|
1627
1710
|
// src/core/challenge-helpers.ts
|