@explorins/pers-sdk-react-native 1.3.2 → 1.5.2
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/README.md +276 -123
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useAnalytics.d.ts +96 -0
- package/dist/hooks/useAnalytics.d.ts.map +1 -0
- package/dist/hooks/useAnalytics.js +73 -0
- package/dist/hooks/useAuth.d.ts +52 -7
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +250 -3
- package/dist/hooks/useBusiness.d.ts +45 -3
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +182 -28
- package/dist/hooks/useCampaigns.d.ts +11 -4
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +101 -39
- package/dist/hooks/useDonations.d.ts +33 -0
- package/dist/hooks/useDonations.d.ts.map +1 -0
- package/dist/hooks/useDonations.js +62 -0
- package/dist/hooks/useFiles.d.ts +50 -0
- package/dist/hooks/useFiles.d.ts.map +1 -0
- package/dist/hooks/useFiles.js +140 -0
- package/dist/hooks/usePurchases.d.ts +9 -0
- package/dist/hooks/usePurchases.d.ts.map +1 -0
- package/dist/hooks/usePurchases.js +56 -0
- package/dist/hooks/useRedemptions.d.ts +10 -5
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +118 -66
- package/dist/hooks/useTenants.d.ts +10 -0
- package/dist/hooks/useTenants.d.ts.map +1 -0
- package/dist/hooks/useTenants.js +68 -0
- package/dist/hooks/useTokens.d.ts +36 -2
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTokens.js +180 -19
- package/dist/hooks/useTransactionSigner.d.ts +73 -0
- package/dist/hooks/useTransactionSigner.d.ts.map +1 -0
- package/dist/hooks/useTransactionSigner.js +216 -0
- package/dist/hooks/useTransactions.d.ts +45 -3
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +149 -39
- package/dist/hooks/useUserStatus.d.ts +9 -0
- package/dist/hooks/useUserStatus.d.ts.map +1 -0
- package/dist/hooks/useUserStatus.js +57 -0
- package/dist/hooks/useUsers.d.ts +17 -0
- package/dist/hooks/useUsers.d.ts.map +1 -0
- package/dist/hooks/useUsers.js +120 -0
- package/dist/hooks/useWeb3.d.ts +69 -6
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/hooks/useWeb3.js +177 -17
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31540 -794
- package/dist/index.js.map +1 -1
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +155 -9
- package/dist/polyfills/web3-polyfills.d.ts +7 -0
- package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
- package/dist/polyfills/web3-polyfills.js +85 -0
- package/dist/providers/PersSDKProvider.d.ts +28 -18
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +63 -129
- package/dist/providers/react-native-auth-provider.d.ts +19 -64
- package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
- package/dist/providers/react-native-auth-provider.js +57 -175
- package/package.json +177 -157
- package/src/hooks/index.ts +13 -1
- package/src/hooks/useAnalytics.ts +150 -0
- package/src/hooks/useAuth.ts +286 -27
- package/src/hooks/useBusiness.ts +193 -30
- package/src/hooks/useCampaigns.ts +121 -43
- package/src/hooks/useDonations.ts +68 -0
- package/src/hooks/useFiles.ts +160 -0
- package/src/hooks/usePurchases.ts +69 -0
- package/src/hooks/useRedemptions.ts +135 -68
- package/src/hooks/useTenants.ts +77 -0
- package/src/hooks/useTokens.ts +189 -21
- package/src/hooks/useTransactionSigner.ts +287 -0
- package/src/hooks/useTransactions.ts +163 -41
- package/src/hooks/useUserStatus.ts +65 -0
- package/src/hooks/useUsers.ts +133 -0
- package/src/hooks/useWeb3.ts +201 -21
- package/src/index.ts +22 -17
- package/src/polyfills/index.ts +163 -10
- package/src/polyfills/web3-polyfills.ts +98 -0
- package/src/providers/PersSDKProvider.tsx +114 -178
- package/src/providers/react-native-auth-provider.ts +65 -208
- package/dist/index.esm.js +0 -1057
- package/dist/index.esm.js.map +0 -1
- package/dist/polyfills/index.simple.d.ts +0 -2
- package/dist/polyfills/index.simple.d.ts.map +0 -1
- package/dist/polyfills/index.simple.js +0 -17
- package/src/polyfills/index.simple.ts +0 -22
- package/src/types/external-modules.d.ts +0 -13
|
@@ -1,92 +1,47 @@
|
|
|
1
1
|
import type { PersAuthProvider } from '@explorins/pers-sdk/core';
|
|
2
|
-
/**
|
|
3
|
-
* Storage strategy for different types of data
|
|
4
|
-
*/
|
|
5
|
-
export declare enum StorageStrategy {
|
|
6
|
-
/** Use AsyncStorage for general app data */
|
|
7
|
-
ASYNC_STORAGE = "async_storage",
|
|
8
|
-
/** Use Keychain for sensitive tokens (when available) */
|
|
9
|
-
KEYCHAIN = "keychain",
|
|
10
|
-
/** Use in-memory storage (fallback) */
|
|
11
|
-
MEMORY = "memory"
|
|
12
|
-
}
|
|
13
2
|
/**
|
|
14
3
|
* Configuration options for React Native Auth Provider
|
|
15
4
|
*/
|
|
16
5
|
export interface ReactNativeAuthConfig {
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/** Storage strategy for refresh tokens */
|
|
20
|
-
refreshTokenStrategy?: StorageStrategy;
|
|
6
|
+
/** Use secure storage (Keychain) for tokens when available */
|
|
7
|
+
useSecureStorage?: boolean;
|
|
21
8
|
/** Custom key prefix for storage */
|
|
22
9
|
keyPrefix?: string;
|
|
23
10
|
/** Enable debug logging */
|
|
24
11
|
debug?: boolean;
|
|
25
12
|
}
|
|
26
13
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* This serves as a blueprint for native implementations and can be extended
|
|
30
|
-
* by consuming applications to integrate with their specific auth systems.
|
|
14
|
+
* React Native Authentication Provider
|
|
31
15
|
*
|
|
32
|
-
*
|
|
33
|
-
* -
|
|
34
|
-
* -
|
|
35
|
-
* -
|
|
36
|
-
* -
|
|
16
|
+
* Simple, unified implementation for React Native apps with:
|
|
17
|
+
* - AsyncStorage for basic token storage
|
|
18
|
+
* - Keychain integration for secure storage (when available)
|
|
19
|
+
* - Automatic fallback to AsyncStorage if Keychain is unavailable
|
|
20
|
+
* - Cross-platform compatibility (iOS/Android/Expo)
|
|
37
21
|
*/
|
|
38
|
-
export declare
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
protected readonly REFRESH_TOKEN_KEY: string;
|
|
45
|
-
protected readonly PROJECT_KEY_KEY: string;
|
|
22
|
+
export declare class ReactNativeAuthProvider implements PersAuthProvider {
|
|
23
|
+
readonly authType: 'user';
|
|
24
|
+
private readonly config;
|
|
25
|
+
private readonly ACCESS_TOKEN_KEY;
|
|
26
|
+
private readonly REFRESH_TOKEN_KEY;
|
|
27
|
+
private readonly projectKey;
|
|
46
28
|
private memoryStorage;
|
|
47
29
|
constructor(projectKey: string, config?: ReactNativeAuthConfig);
|
|
30
|
+
getProjectKey(): Promise<string | null>;
|
|
48
31
|
getToken(): Promise<string | null>;
|
|
49
32
|
setAccessToken(token: string): Promise<void>;
|
|
50
33
|
setRefreshToken(token: string): Promise<void>;
|
|
51
34
|
getRefreshToken(): Promise<string | null>;
|
|
52
35
|
clearTokens(): Promise<void>;
|
|
36
|
+
onTokenExpired(): Promise<void>;
|
|
53
37
|
hasValidToken(): boolean;
|
|
54
38
|
hasRefreshToken(): boolean;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
clearToken(): void;
|
|
59
|
-
protected storeValue(key: string, value: string, strategy: StorageStrategy): Promise<void>;
|
|
60
|
-
protected getStoredValue(key: string, strategy: StorageStrategy): Promise<string | null>;
|
|
61
|
-
protected removeStoredValue(key: string, strategy: StorageStrategy): Promise<void>;
|
|
39
|
+
private storeValue;
|
|
40
|
+
private getStoredValue;
|
|
41
|
+
private removeStoredValue;
|
|
62
42
|
private isKeychainAvailable;
|
|
63
43
|
private storeInKeychain;
|
|
64
44
|
private getFromKeychain;
|
|
65
45
|
private removeFromKeychain;
|
|
66
46
|
}
|
|
67
|
-
/**
|
|
68
|
-
* React Native Authentication Provider
|
|
69
|
-
*
|
|
70
|
-
* A ready-to-use implementation for basic use cases.
|
|
71
|
-
* Uses AsyncStorage for access tokens and Keychain for refresh tokens (when available).
|
|
72
|
-
*/
|
|
73
|
-
export declare class ReactNativeAuthProvider extends BaseReactNativeAuthProvider {
|
|
74
|
-
private projectKey;
|
|
75
|
-
readonly authType: 'user';
|
|
76
|
-
constructor(projectKey: string, config?: ReactNativeAuthConfig);
|
|
77
|
-
getProjectKey(): Promise<string | null>;
|
|
78
|
-
onTokenExpired(): Promise<void>;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Secure React Native Authentication Provider
|
|
82
|
-
*
|
|
83
|
-
* Maximum security implementation using Keychain for all sensitive data.
|
|
84
|
-
*/
|
|
85
|
-
export declare class SecureReactNativeAuthProvider extends BaseReactNativeAuthProvider {
|
|
86
|
-
private projectKey;
|
|
87
|
-
readonly authType: 'user';
|
|
88
|
-
constructor(projectKey: string, config?: Omit<ReactNativeAuthConfig, 'accessTokenStrategy' | 'refreshTokenStrategy'>);
|
|
89
|
-
getProjectKey(): Promise<string | null>;
|
|
90
|
-
onTokenExpired(): Promise<void>;
|
|
91
|
-
}
|
|
92
47
|
//# sourceMappingURL=react-native-auth-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native-auth-provider.d.ts","sourceRoot":"","sources":["../../src/providers/react-native-auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"react-native-auth-provider.d.ts","sourceRoot":"","sources":["../../src/providers/react-native-auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAU;IAEnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAGpC,OAAO,CAAC,aAAa,CAAkC;gBAGrD,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,qBAA0B;IA4B9B,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIvC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIlC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7C,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IASrC,aAAa,IAAI,OAAO;IAIxB,eAAe,IAAI,OAAO;YAKZ,UAAU;YAcV,cAAc;YAcd,iBAAiB;YAgBjB,mBAAmB;YASnB,eAAe;YAKf,eAAe;YAMf,kBAAkB;CAIjC"}
|
|
@@ -1,40 +1,25 @@
|
|
|
1
1
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
export var StorageStrategy;
|
|
6
|
-
(function (StorageStrategy) {
|
|
7
|
-
/** Use AsyncStorage for general app data */
|
|
8
|
-
StorageStrategy["ASYNC_STORAGE"] = "async_storage";
|
|
9
|
-
/** Use Keychain for sensitive tokens (when available) */
|
|
10
|
-
StorageStrategy["KEYCHAIN"] = "keychain";
|
|
11
|
-
/** Use in-memory storage (fallback) */
|
|
12
|
-
StorageStrategy["MEMORY"] = "memory";
|
|
13
|
-
})(StorageStrategy || (StorageStrategy = {}));
|
|
14
|
-
/**
|
|
15
|
-
* Base React Native Authentication Provider
|
|
16
|
-
*
|
|
17
|
-
* This serves as a blueprint for native implementations and can be extended
|
|
18
|
-
* by consuming applications to integrate with their specific auth systems.
|
|
3
|
+
* React Native Authentication Provider
|
|
19
4
|
*
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
-
* -
|
|
23
|
-
* -
|
|
24
|
-
* -
|
|
5
|
+
* Simple, unified implementation for React Native apps with:
|
|
6
|
+
* - AsyncStorage for basic token storage
|
|
7
|
+
* - Keychain integration for secure storage (when available)
|
|
8
|
+
* - Automatic fallback to AsyncStorage if Keychain is unavailable
|
|
9
|
+
* - Cross-platform compatibility (iOS/Android/Expo)
|
|
25
10
|
*/
|
|
26
|
-
export class
|
|
11
|
+
export class ReactNativeAuthProvider {
|
|
27
12
|
constructor(projectKey, config = {}) {
|
|
13
|
+
this.authType = 'user';
|
|
28
14
|
// In-memory fallback storage
|
|
29
15
|
this.memoryStorage = new Map();
|
|
30
|
-
// Validate projectKey
|
|
31
16
|
if (!projectKey || typeof projectKey !== 'string') {
|
|
32
17
|
throw new Error('ReactNativeAuthProvider: projectKey is required and must be a string');
|
|
33
18
|
}
|
|
19
|
+
this.projectKey = projectKey;
|
|
34
20
|
// Set default configuration
|
|
35
21
|
this.config = {
|
|
36
|
-
|
|
37
|
-
refreshTokenStrategy: StorageStrategy.KEYCHAIN,
|
|
22
|
+
useSecureStorage: true, // Default to secure storage when available
|
|
38
23
|
keyPrefix: `pers_${projectKey.slice(0, 8)}`,
|
|
39
24
|
debug: false,
|
|
40
25
|
...config
|
|
@@ -42,151 +27,106 @@ export class BaseReactNativeAuthProvider {
|
|
|
42
27
|
// Create storage keys
|
|
43
28
|
this.ACCESS_TOKEN_KEY = `${this.config.keyPrefix}_access_token`;
|
|
44
29
|
this.REFRESH_TOKEN_KEY = `${this.config.keyPrefix}_refresh_token`;
|
|
45
|
-
this.PROJECT_KEY_KEY = `${this.config.keyPrefix}_project_key`;
|
|
46
30
|
if (this.config.debug) {
|
|
47
|
-
console.log('
|
|
31
|
+
console.log('ReactNativeAuthProvider initialized:', {
|
|
32
|
+
projectKey: projectKey.slice(0, 8) + '...',
|
|
33
|
+
useSecureStorage: this.config.useSecureStorage
|
|
34
|
+
});
|
|
48
35
|
}
|
|
49
36
|
}
|
|
50
|
-
|
|
37
|
+
async getProjectKey() {
|
|
38
|
+
return this.projectKey;
|
|
39
|
+
}
|
|
51
40
|
async getToken() {
|
|
52
|
-
return this.getStoredValue(this.ACCESS_TOKEN_KEY
|
|
41
|
+
return this.getStoredValue(this.ACCESS_TOKEN_KEY);
|
|
53
42
|
}
|
|
54
43
|
async setAccessToken(token) {
|
|
55
|
-
await this.storeValue(this.ACCESS_TOKEN_KEY, token
|
|
44
|
+
await this.storeValue(this.ACCESS_TOKEN_KEY, token);
|
|
56
45
|
if (this.config.debug) {
|
|
57
|
-
console.log('
|
|
46
|
+
console.log('Access token stored securely');
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
49
|
async setRefreshToken(token) {
|
|
61
|
-
await this.storeValue(this.REFRESH_TOKEN_KEY, token
|
|
50
|
+
await this.storeValue(this.REFRESH_TOKEN_KEY, token);
|
|
62
51
|
if (this.config.debug) {
|
|
63
|
-
console.log('
|
|
52
|
+
console.log('Refresh token stored securely');
|
|
64
53
|
}
|
|
65
54
|
}
|
|
66
55
|
async getRefreshToken() {
|
|
67
|
-
return this.getStoredValue(this.REFRESH_TOKEN_KEY
|
|
56
|
+
return this.getStoredValue(this.REFRESH_TOKEN_KEY);
|
|
68
57
|
}
|
|
69
58
|
async clearTokens() {
|
|
70
59
|
await Promise.all([
|
|
71
|
-
this.removeStoredValue(this.ACCESS_TOKEN_KEY
|
|
72
|
-
this.removeStoredValue(this.REFRESH_TOKEN_KEY
|
|
60
|
+
this.removeStoredValue(this.ACCESS_TOKEN_KEY),
|
|
61
|
+
this.removeStoredValue(this.REFRESH_TOKEN_KEY)
|
|
73
62
|
]);
|
|
74
63
|
if (this.config.debug) {
|
|
75
|
-
console.log('
|
|
64
|
+
console.log('All tokens cleared from storage');
|
|
76
65
|
}
|
|
77
66
|
}
|
|
67
|
+
async onTokenExpired() {
|
|
68
|
+
if (this.config.debug) {
|
|
69
|
+
console.warn('ReactNativeAuthProvider: Token expired - implement refresh logic in your app');
|
|
70
|
+
}
|
|
71
|
+
// Clear expired tokens
|
|
72
|
+
await this.clearTokens();
|
|
73
|
+
}
|
|
78
74
|
// Token validation methods
|
|
79
75
|
hasValidToken() {
|
|
80
|
-
// Synchronous check - for async check use hasValidTokenAsync()
|
|
81
76
|
return true; // Actual validation happens in getToken()
|
|
82
77
|
}
|
|
83
78
|
hasRefreshToken() {
|
|
84
|
-
// Synchronous check - for async check use hasRefreshTokenAsync()
|
|
85
79
|
return true; // Actual validation happens in getRefreshToken()
|
|
86
80
|
}
|
|
87
|
-
//
|
|
88
|
-
async
|
|
89
|
-
const token = await this.getToken();
|
|
90
|
-
return !!token;
|
|
91
|
-
}
|
|
92
|
-
async hasRefreshTokenAsync() {
|
|
93
|
-
const refreshToken = await this.getRefreshToken();
|
|
94
|
-
return !!refreshToken;
|
|
95
|
-
}
|
|
96
|
-
// Legacy methods for backward compatibility
|
|
97
|
-
setToken(token) {
|
|
98
|
-
this.setAccessToken(token).catch(error => {
|
|
99
|
-
console.error('Legacy setToken failed:', error);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
clearToken() {
|
|
103
|
-
this.clearTokens().catch(error => {
|
|
104
|
-
console.error('Legacy clearToken failed:', error);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
// Protected storage implementation methods
|
|
108
|
-
async storeValue(key, value, strategy) {
|
|
81
|
+
// Storage implementation methods
|
|
82
|
+
async storeValue(key, value) {
|
|
109
83
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
await AsyncStorage.setItem(key, value);
|
|
118
|
-
}
|
|
119
|
-
break;
|
|
120
|
-
case StorageStrategy.ASYNC_STORAGE:
|
|
121
|
-
await AsyncStorage.setItem(key, value);
|
|
122
|
-
break;
|
|
123
|
-
case StorageStrategy.MEMORY:
|
|
124
|
-
default:
|
|
125
|
-
this.memoryStorage.set(key, value);
|
|
126
|
-
break;
|
|
84
|
+
if (this.config.useSecureStorage && await this.isKeychainAvailable()) {
|
|
85
|
+
await this.storeInKeychain(key, value);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await AsyncStorage.setItem(key, value);
|
|
127
89
|
}
|
|
128
90
|
}
|
|
129
91
|
catch (error) {
|
|
130
|
-
console.error(`Failed to store value
|
|
92
|
+
console.error(`Failed to store value for key ${key}:`, error);
|
|
131
93
|
// Fallback to memory storage
|
|
132
94
|
this.memoryStorage.set(key, value);
|
|
133
95
|
}
|
|
134
96
|
}
|
|
135
|
-
async getStoredValue(key
|
|
97
|
+
async getStoredValue(key) {
|
|
136
98
|
try {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
return await AsyncStorage.getItem(key);
|
|
145
|
-
}
|
|
146
|
-
case StorageStrategy.ASYNC_STORAGE:
|
|
147
|
-
return await AsyncStorage.getItem(key);
|
|
148
|
-
case StorageStrategy.MEMORY:
|
|
149
|
-
default:
|
|
150
|
-
return this.memoryStorage.get(key) || null;
|
|
99
|
+
if (this.config.useSecureStorage && await this.isKeychainAvailable()) {
|
|
100
|
+
return await this.getFromKeychain(key);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return await AsyncStorage.getItem(key);
|
|
151
104
|
}
|
|
152
105
|
}
|
|
153
106
|
catch (error) {
|
|
154
|
-
console.warn(`Failed to get value
|
|
107
|
+
console.warn(`Failed to get value for key ${key}:`, error);
|
|
155
108
|
// Fallback to memory storage
|
|
156
109
|
return this.memoryStorage.get(key) || null;
|
|
157
110
|
}
|
|
158
111
|
}
|
|
159
|
-
async removeStoredValue(key
|
|
112
|
+
async removeStoredValue(key) {
|
|
160
113
|
try {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
await AsyncStorage.removeItem(key);
|
|
169
|
-
}
|
|
170
|
-
break;
|
|
171
|
-
case StorageStrategy.ASYNC_STORAGE:
|
|
172
|
-
await AsyncStorage.removeItem(key);
|
|
173
|
-
break;
|
|
174
|
-
case StorageStrategy.MEMORY:
|
|
175
|
-
default:
|
|
176
|
-
this.memoryStorage.delete(key);
|
|
177
|
-
break;
|
|
114
|
+
if (this.config.useSecureStorage && await this.isKeychainAvailable()) {
|
|
115
|
+
await this.removeFromKeychain(key);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
await AsyncStorage.removeItem(key);
|
|
178
119
|
}
|
|
179
120
|
}
|
|
180
121
|
catch (error) {
|
|
181
|
-
console.error(`Failed to remove value
|
|
182
|
-
// Ensure memory fallback is also cleared
|
|
183
|
-
this.memoryStorage.delete(key);
|
|
122
|
+
console.error(`Failed to remove value for key ${key}:`, error);
|
|
184
123
|
}
|
|
124
|
+
// Ensure memory fallback is also cleared
|
|
125
|
+
this.memoryStorage.delete(key);
|
|
185
126
|
}
|
|
186
127
|
// Keychain helper methods
|
|
187
128
|
async isKeychainAvailable() {
|
|
188
129
|
try {
|
|
189
|
-
// Check if react-native-keychain is available
|
|
190
130
|
const Keychain = require('react-native-keychain');
|
|
191
131
|
return !!Keychain && typeof Keychain.setInternetCredentials === 'function';
|
|
192
132
|
}
|
|
@@ -208,61 +148,3 @@ export class BaseReactNativeAuthProvider {
|
|
|
208
148
|
await Keychain.resetInternetCredentials(key);
|
|
209
149
|
}
|
|
210
150
|
}
|
|
211
|
-
/**
|
|
212
|
-
* React Native Authentication Provider
|
|
213
|
-
*
|
|
214
|
-
* A ready-to-use implementation for basic use cases.
|
|
215
|
-
* Uses AsyncStorage for access tokens and Keychain for refresh tokens (when available).
|
|
216
|
-
*/
|
|
217
|
-
export class ReactNativeAuthProvider extends BaseReactNativeAuthProvider {
|
|
218
|
-
constructor(projectKey, config = {}) {
|
|
219
|
-
// Validate projectKey
|
|
220
|
-
if (!projectKey || typeof projectKey !== 'string') {
|
|
221
|
-
throw new Error('ReactNativeAuthProvider: projectKey is required and must be a string');
|
|
222
|
-
}
|
|
223
|
-
super(projectKey, {
|
|
224
|
-
accessTokenStrategy: StorageStrategy.ASYNC_STORAGE,
|
|
225
|
-
refreshTokenStrategy: StorageStrategy.KEYCHAIN,
|
|
226
|
-
debug: false,
|
|
227
|
-
...config
|
|
228
|
-
});
|
|
229
|
-
this.projectKey = projectKey;
|
|
230
|
-
this.authType = 'user';
|
|
231
|
-
}
|
|
232
|
-
async getProjectKey() {
|
|
233
|
-
return this.projectKey;
|
|
234
|
-
}
|
|
235
|
-
async onTokenExpired() {
|
|
236
|
-
if (this.config.debug) {
|
|
237
|
-
console.warn('ReactNativeAuthProvider: Token expired - no refresh logic implemented');
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Secure React Native Authentication Provider
|
|
243
|
-
*
|
|
244
|
-
* Maximum security implementation using Keychain for all sensitive data.
|
|
245
|
-
*/
|
|
246
|
-
export class SecureReactNativeAuthProvider extends BaseReactNativeAuthProvider {
|
|
247
|
-
constructor(projectKey, config = {}) {
|
|
248
|
-
// Validate projectKey
|
|
249
|
-
if (!projectKey || typeof projectKey !== 'string') {
|
|
250
|
-
throw new Error('SecureReactNativeAuthProvider: projectKey is required and must be a string');
|
|
251
|
-
}
|
|
252
|
-
super(projectKey, {
|
|
253
|
-
...config,
|
|
254
|
-
accessTokenStrategy: StorageStrategy.KEYCHAIN,
|
|
255
|
-
refreshTokenStrategy: StorageStrategy.KEYCHAIN,
|
|
256
|
-
});
|
|
257
|
-
this.projectKey = projectKey;
|
|
258
|
-
this.authType = 'user';
|
|
259
|
-
}
|
|
260
|
-
async getProjectKey() {
|
|
261
|
-
return this.projectKey;
|
|
262
|
-
}
|
|
263
|
-
async onTokenExpired() {
|
|
264
|
-
if (this.config.debug) {
|
|
265
|
-
console.warn('SecureReactNativeAuthProvider: Token expired - implement refresh logic');
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|