@nauth-toolkit/client 0.1.83 → 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.d.mts
CHANGED
|
@@ -1254,8 +1254,21 @@ declare class ChallengeRouter {
|
|
|
1254
1254
|
navigateToChallenge(response: AuthResponse): Promise<void>;
|
|
1255
1255
|
/**
|
|
1256
1256
|
* Navigate to success URL.
|
|
1257
|
+
*
|
|
1258
|
+
* @param queryParams - Optional query parameters to append to the success URL
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```typescript
|
|
1262
|
+
* await router.navigateToSuccess({ appState: 'invite-code-123' });
|
|
1263
|
+
* ```
|
|
1257
1264
|
*/
|
|
1258
|
-
navigateToSuccess(): Promise<void>;
|
|
1265
|
+
navigateToSuccess(queryParams?: Record<string, string>): Promise<void>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Retrieve stored OAuth appState from storage.
|
|
1268
|
+
*
|
|
1269
|
+
* @returns Query params object with appState if present, undefined otherwise
|
|
1270
|
+
*/
|
|
1271
|
+
private getStoredOauthState;
|
|
1259
1272
|
/**
|
|
1260
1273
|
* Navigate to error URL.
|
|
1261
1274
|
*
|
|
@@ -1761,6 +1774,42 @@ declare class NAuthClient {
|
|
|
1761
1774
|
* ```
|
|
1762
1775
|
*/
|
|
1763
1776
|
getChallengeRouter(): ChallengeRouter;
|
|
1777
|
+
/**
|
|
1778
|
+
* Store OAuth appState from social redirect callback.
|
|
1779
|
+
*
|
|
1780
|
+
* This is called automatically by the social redirect callback guard
|
|
1781
|
+
* when appState is present in the callback URL. The stored state can
|
|
1782
|
+
* be retrieved using getLastOauthState().
|
|
1783
|
+
*
|
|
1784
|
+
* @param appState - OAuth appState value from callback URL
|
|
1785
|
+
*
|
|
1786
|
+
* @example
|
|
1787
|
+
* ```typescript
|
|
1788
|
+
* await client.storeOauthState('invite-code-123');
|
|
1789
|
+
* ```
|
|
1790
|
+
*/
|
|
1791
|
+
storeOauthState(appState: string): Promise<void>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Get the last OAuth appState from social redirect callback.
|
|
1794
|
+
*
|
|
1795
|
+
* Returns the appState that was stored during the most recent social
|
|
1796
|
+
* login redirect callback. This is useful for restoring UI state,
|
|
1797
|
+
* applying invite codes, or tracking referral information.
|
|
1798
|
+
*
|
|
1799
|
+
* The state is automatically cleared after retrieval to prevent reuse.
|
|
1800
|
+
*
|
|
1801
|
+
* @returns The stored appState, or null if none exists
|
|
1802
|
+
*
|
|
1803
|
+
* @example
|
|
1804
|
+
* ```typescript
|
|
1805
|
+
* const appState = await client.getLastOauthState();
|
|
1806
|
+
* if (appState) {
|
|
1807
|
+
* // Apply invite code or restore UI state
|
|
1808
|
+
* console.log('OAuth state:', appState);
|
|
1809
|
+
* }
|
|
1810
|
+
* ```
|
|
1811
|
+
*/
|
|
1812
|
+
getLastOauthState(): Promise<string | null>;
|
|
1764
1813
|
}
|
|
1765
1814
|
|
|
1766
1815
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1254,8 +1254,21 @@ declare class ChallengeRouter {
|
|
|
1254
1254
|
navigateToChallenge(response: AuthResponse): Promise<void>;
|
|
1255
1255
|
/**
|
|
1256
1256
|
* Navigate to success URL.
|
|
1257
|
+
*
|
|
1258
|
+
* @param queryParams - Optional query parameters to append to the success URL
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```typescript
|
|
1262
|
+
* await router.navigateToSuccess({ appState: 'invite-code-123' });
|
|
1263
|
+
* ```
|
|
1257
1264
|
*/
|
|
1258
|
-
navigateToSuccess(): Promise<void>;
|
|
1265
|
+
navigateToSuccess(queryParams?: Record<string, string>): Promise<void>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Retrieve stored OAuth appState from storage.
|
|
1268
|
+
*
|
|
1269
|
+
* @returns Query params object with appState if present, undefined otherwise
|
|
1270
|
+
*/
|
|
1271
|
+
private getStoredOauthState;
|
|
1259
1272
|
/**
|
|
1260
1273
|
* Navigate to error URL.
|
|
1261
1274
|
*
|
|
@@ -1761,6 +1774,42 @@ declare class NAuthClient {
|
|
|
1761
1774
|
* ```
|
|
1762
1775
|
*/
|
|
1763
1776
|
getChallengeRouter(): ChallengeRouter;
|
|
1777
|
+
/**
|
|
1778
|
+
* Store OAuth appState from social redirect callback.
|
|
1779
|
+
*
|
|
1780
|
+
* This is called automatically by the social redirect callback guard
|
|
1781
|
+
* when appState is present in the callback URL. The stored state can
|
|
1782
|
+
* be retrieved using getLastOauthState().
|
|
1783
|
+
*
|
|
1784
|
+
* @param appState - OAuth appState value from callback URL
|
|
1785
|
+
*
|
|
1786
|
+
* @example
|
|
1787
|
+
* ```typescript
|
|
1788
|
+
* await client.storeOauthState('invite-code-123');
|
|
1789
|
+
* ```
|
|
1790
|
+
*/
|
|
1791
|
+
storeOauthState(appState: string): Promise<void>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Get the last OAuth appState from social redirect callback.
|
|
1794
|
+
*
|
|
1795
|
+
* Returns the appState that was stored during the most recent social
|
|
1796
|
+
* login redirect callback. This is useful for restoring UI state,
|
|
1797
|
+
* applying invite codes, or tracking referral information.
|
|
1798
|
+
*
|
|
1799
|
+
* The state is automatically cleared after retrieval to prevent reuse.
|
|
1800
|
+
*
|
|
1801
|
+
* @returns The stored appState, or null if none exists
|
|
1802
|
+
*
|
|
1803
|
+
* @example
|
|
1804
|
+
* ```typescript
|
|
1805
|
+
* const appState = await client.getLastOauthState();
|
|
1806
|
+
* if (appState) {
|
|
1807
|
+
* // Apply invite code or restore UI state
|
|
1808
|
+
* console.log('OAuth state:', appState);
|
|
1809
|
+
* }
|
|
1810
|
+
* ```
|
|
1811
|
+
*/
|
|
1812
|
+
getLastOauthState(): Promise<string | null>;
|
|
1764
1813
|
}
|
|
1765
1814
|
|
|
1766
1815
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -528,6 +528,7 @@ var FetchAdapter = class {
|
|
|
528
528
|
};
|
|
529
529
|
|
|
530
530
|
// src/core/challenge-router.ts
|
|
531
|
+
var OAUTH_STATE_KEY = "nauth_oauth_state";
|
|
531
532
|
var ChallengeRouter = class {
|
|
532
533
|
constructor(config) {
|
|
533
534
|
this.config = config;
|
|
@@ -546,7 +547,8 @@ var ChallengeRouter = class {
|
|
|
546
547
|
if (response.challengeName) {
|
|
547
548
|
await this.navigateToChallenge(response);
|
|
548
549
|
} else {
|
|
549
|
-
await this.
|
|
550
|
+
const queryParams = await this.getStoredOauthState();
|
|
551
|
+
await this.navigateToSuccess(queryParams);
|
|
550
552
|
}
|
|
551
553
|
}
|
|
552
554
|
/**
|
|
@@ -560,11 +562,44 @@ var ChallengeRouter = class {
|
|
|
560
562
|
}
|
|
561
563
|
/**
|
|
562
564
|
* Navigate to success URL.
|
|
565
|
+
*
|
|
566
|
+
* @param queryParams - Optional query parameters to append to the success URL
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* await router.navigateToSuccess({ appState: 'invite-code-123' });
|
|
571
|
+
* ```
|
|
563
572
|
*/
|
|
564
|
-
async navigateToSuccess() {
|
|
565
|
-
|
|
573
|
+
async navigateToSuccess(queryParams) {
|
|
574
|
+
let url = this.config.redirects?.success || "/";
|
|
575
|
+
if (queryParams && Object.keys(queryParams).length > 0) {
|
|
576
|
+
const searchParams = new URLSearchParams();
|
|
577
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
578
|
+
if (value) {
|
|
579
|
+
searchParams.set(key, value);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
const queryString = searchParams.toString();
|
|
583
|
+
url = queryString ? `${url}${url.includes("?") ? "&" : "?"}${queryString}` : url;
|
|
584
|
+
}
|
|
566
585
|
await this.navigate(url);
|
|
567
586
|
}
|
|
587
|
+
/**
|
|
588
|
+
* Retrieve stored OAuth appState from storage.
|
|
589
|
+
*
|
|
590
|
+
* @returns Query params object with appState if present, undefined otherwise
|
|
591
|
+
*/
|
|
592
|
+
async getStoredOauthState() {
|
|
593
|
+
try {
|
|
594
|
+
const stored = await this.config.storage.getItem(OAUTH_STATE_KEY);
|
|
595
|
+
if (stored) {
|
|
596
|
+
await this.config.storage.removeItem(OAUTH_STATE_KEY);
|
|
597
|
+
return { appState: stored };
|
|
598
|
+
}
|
|
599
|
+
} catch {
|
|
600
|
+
}
|
|
601
|
+
return void 0;
|
|
602
|
+
}
|
|
568
603
|
/**
|
|
569
604
|
* Navigate to error URL.
|
|
570
605
|
*
|
|
@@ -679,6 +714,7 @@ var ChallengeRouter = class {
|
|
|
679
714
|
// src/core/client.ts
|
|
680
715
|
var USER_KEY2 = "nauth_user";
|
|
681
716
|
var CHALLENGE_KEY2 = "nauth_challenge_session";
|
|
717
|
+
var OAUTH_STATE_KEY2 = "nauth_oauth_state";
|
|
682
718
|
var hasWindow = () => typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined";
|
|
683
719
|
var defaultStorage = () => {
|
|
684
720
|
if (hasWindow() && typeof window.localStorage !== "undefined") {
|
|
@@ -1582,6 +1618,53 @@ var NAuthClient = class {
|
|
|
1582
1618
|
getChallengeRouter() {
|
|
1583
1619
|
return this.challengeRouter;
|
|
1584
1620
|
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Store OAuth appState from social redirect callback.
|
|
1623
|
+
*
|
|
1624
|
+
* This is called automatically by the social redirect callback guard
|
|
1625
|
+
* when appState is present in the callback URL. The stored state can
|
|
1626
|
+
* be retrieved using getLastOauthState().
|
|
1627
|
+
*
|
|
1628
|
+
* @param appState - OAuth appState value from callback URL
|
|
1629
|
+
*
|
|
1630
|
+
* @example
|
|
1631
|
+
* ```typescript
|
|
1632
|
+
* await client.storeOauthState('invite-code-123');
|
|
1633
|
+
* ```
|
|
1634
|
+
*/
|
|
1635
|
+
async storeOauthState(appState) {
|
|
1636
|
+
if (appState && appState.trim() !== "") {
|
|
1637
|
+
await this.config.storage.setItem(OAUTH_STATE_KEY2, appState);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Get the last OAuth appState from social redirect callback.
|
|
1642
|
+
*
|
|
1643
|
+
* Returns the appState that was stored during the most recent social
|
|
1644
|
+
* login redirect callback. This is useful for restoring UI state,
|
|
1645
|
+
* applying invite codes, or tracking referral information.
|
|
1646
|
+
*
|
|
1647
|
+
* The state is automatically cleared after retrieval to prevent reuse.
|
|
1648
|
+
*
|
|
1649
|
+
* @returns The stored appState, or null if none exists
|
|
1650
|
+
*
|
|
1651
|
+
* @example
|
|
1652
|
+
* ```typescript
|
|
1653
|
+
* const appState = await client.getLastOauthState();
|
|
1654
|
+
* if (appState) {
|
|
1655
|
+
* // Apply invite code or restore UI state
|
|
1656
|
+
* console.log('OAuth state:', appState);
|
|
1657
|
+
* }
|
|
1658
|
+
* ```
|
|
1659
|
+
*/
|
|
1660
|
+
async getLastOauthState() {
|
|
1661
|
+
const stored = await this.config.storage.getItem(OAUTH_STATE_KEY2);
|
|
1662
|
+
if (stored) {
|
|
1663
|
+
await this.config.storage.removeItem(OAUTH_STATE_KEY2);
|
|
1664
|
+
return stored;
|
|
1665
|
+
}
|
|
1666
|
+
return null;
|
|
1667
|
+
}
|
|
1585
1668
|
};
|
|
1586
1669
|
|
|
1587
1670
|
// src/core/challenge-helpers.ts
|