@onairos/react-native 3.0.71 โ 3.0.73
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/lib/commonjs/components/Onairos.js +294 -155
- package/lib/commonjs/components/Onairos.js.map +1 -1
- package/lib/commonjs/components/OnairosButton.js +1 -1
- package/lib/commonjs/components/OnairosButton.js.map +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +6 -6
- package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
- package/lib/commonjs/components/onboarding/OAuthWebView.js +188 -52
- package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/commonjs/index.js +25 -440
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/apiKeyService.js +404 -0
- package/lib/commonjs/services/apiKeyService.js.map +1 -0
- package/lib/commonjs/services/platformAuthService.js +318 -113
- package/lib/commonjs/services/platformAuthService.js.map +1 -1
- package/lib/commonjs/types/index.js +4 -0
- package/lib/commonjs/types.js +12 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/programmaticFlow.js +117 -0
- package/lib/commonjs/utils/programmaticFlow.js.map +1 -0
- package/lib/module/components/Onairos.js +297 -158
- package/lib/module/components/Onairos.js.map +1 -1
- package/lib/module/components/OnairosButton.js +1 -1
- package/lib/module/components/OnairosButton.js.map +1 -1
- package/lib/module/components/UniversalOnboarding.js +6 -6
- package/lib/module/components/UniversalOnboarding.js.map +1 -1
- package/lib/module/components/onboarding/OAuthWebView.js +188 -52
- package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/module/index.js +17 -61
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/apiKeyService.js +389 -0
- package/lib/module/services/apiKeyService.js.map +1 -0
- package/lib/module/services/platformAuthService.js +311 -111
- package/lib/module/services/platformAuthService.js.map +1 -1
- package/lib/module/types/index.js +1 -1
- package/lib/module/types.js +8 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/programmaticFlow.js +111 -0
- package/lib/module/utils/programmaticFlow.js.map +1 -0
- package/lib/typescript/components/Onairos.d.ts +2 -29
- package/lib/typescript/components/Onairos.d.ts.map +1 -1
- package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +10 -39
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/services/apiKeyService.d.ts +66 -0
- package/lib/typescript/services/apiKeyService.d.ts.map +1 -0
- package/lib/typescript/services/platformAuthService.d.ts +26 -0
- package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
- package/lib/typescript/types/index.d.ts +144 -78
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +92 -3
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/programmaticFlow.d.ts +23 -0
- package/lib/typescript/utils/programmaticFlow.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/Onairos.tsx +330 -207
- package/src/components/OnairosButton.tsx +1 -1
- package/src/components/UniversalOnboarding.tsx +6 -6
- package/src/components/onboarding/OAuthWebView.tsx +236 -71
- package/src/index.ts +25 -115
- package/src/services/apiKeyService.ts +401 -0
- package/src/services/platformAuthService.ts +363 -126
- package/src/types/index.d.ts +110 -0
- package/src/types/index.ts +148 -74
- package/src/types.ts +99 -3
- package/src/utils/programmaticFlow.ts +113 -0
|
@@ -1,20 +1,64 @@
|
|
|
1
1
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
import { makeAuthenticatedRequest } from './apiKeyService';
|
|
2
3
|
|
|
3
|
-
//
|
|
4
|
+
// ๐ CRITICAL: Initialize API key service for authentication
|
|
5
|
+
let isApiKeyInitialized = false;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the API key service with the admin key for testing
|
|
9
|
+
* This ensures all API requests include proper authentication headers
|
|
10
|
+
*/
|
|
11
|
+
export const initializePlatformAuthService = async () => {
|
|
12
|
+
if (isApiKeyInitialized) {
|
|
13
|
+
console.log('๐ API key service already initialized');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
// Import the initialization function
|
|
18
|
+
const {
|
|
19
|
+
initializeApiKey,
|
|
20
|
+
ADMIN_API_KEY
|
|
21
|
+
} = await import('./apiKeyService');
|
|
22
|
+
|
|
23
|
+
// Initialize with admin key for testing/development
|
|
24
|
+
await initializeApiKey({
|
|
25
|
+
apiKey: ADMIN_API_KEY,
|
|
26
|
+
// 'OnairosIsAUnicorn2025'
|
|
27
|
+
environment: 'development',
|
|
28
|
+
enableLogging: true,
|
|
29
|
+
timeout: 30000
|
|
30
|
+
});
|
|
31
|
+
isApiKeyInitialized = true;
|
|
32
|
+
console.log('โ
Platform auth service initialized with admin key');
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('โ Failed to initialize platform auth service:', error);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Ensure API key is initialized before making authenticated requests
|
|
41
|
+
*/
|
|
42
|
+
const ensureApiKeyInitialized = async () => {
|
|
43
|
+
if (!isApiKeyInitialized) {
|
|
44
|
+
console.log('๐ API key not initialized, initializing now...');
|
|
45
|
+
await initializePlatformAuthService();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
4
48
|
|
|
5
49
|
// Configuration for each platform's authentication
|
|
6
50
|
let PLATFORM_AUTH_CONFIG = {
|
|
7
51
|
instagram: {
|
|
8
52
|
hasNativeSDK: false,
|
|
9
53
|
// Instagram uses OAuth WebView flow
|
|
10
|
-
authEndpoint: '
|
|
54
|
+
authEndpoint: '/instagram/authorize',
|
|
11
55
|
color: '#E1306C'
|
|
12
56
|
},
|
|
13
57
|
youtube: {
|
|
14
58
|
hasNativeSDK: true,
|
|
15
59
|
// Native Google Sign-In SDK enabled
|
|
16
60
|
nativeSDKPackage: '@react-native-google-signin/google-signin',
|
|
17
|
-
authEndpoint: '
|
|
61
|
+
authEndpoint: '/youtube/authorize',
|
|
18
62
|
color: '#FF0000',
|
|
19
63
|
clientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
|
|
20
64
|
redirectUri: 'onairosevents://auth/callback',
|
|
@@ -23,17 +67,17 @@ let PLATFORM_AUTH_CONFIG = {
|
|
|
23
67
|
},
|
|
24
68
|
reddit: {
|
|
25
69
|
hasNativeSDK: false,
|
|
26
|
-
authEndpoint: '
|
|
70
|
+
authEndpoint: '/reddit/authorize',
|
|
27
71
|
color: '#FF4500'
|
|
28
72
|
},
|
|
29
73
|
pinterest: {
|
|
30
74
|
hasNativeSDK: false,
|
|
31
|
-
authEndpoint: '
|
|
75
|
+
authEndpoint: '/pinterest/authorize',
|
|
32
76
|
color: '#E60023'
|
|
33
77
|
},
|
|
34
78
|
email: {
|
|
35
79
|
hasNativeSDK: false,
|
|
36
|
-
authEndpoint: '
|
|
80
|
+
authEndpoint: '/gmail/authorize',
|
|
37
81
|
color: '#4285F4'
|
|
38
82
|
}
|
|
39
83
|
};
|
|
@@ -109,30 +153,11 @@ export const initiateOAuth = async (platform, username, appName) => {
|
|
|
109
153
|
}
|
|
110
154
|
};
|
|
111
155
|
console.log('๐ค Sending Instagram OAuth request:', jsonData);
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
response = await fetch('https://api2.onairos.uk/instagram/authorize', {
|
|
118
|
-
method: 'POST',
|
|
119
|
-
headers: {
|
|
120
|
-
'Content-Type': 'application/json',
|
|
121
|
-
'User-Agent': 'OnairosReactNative/1.0'
|
|
122
|
-
},
|
|
123
|
-
body: JSON.stringify(jsonData),
|
|
124
|
-
signal: controller.signal
|
|
125
|
-
});
|
|
126
|
-
} catch (fetchError) {
|
|
127
|
-
clearTimeout(timeoutId);
|
|
128
|
-
if (fetchError.name === 'AbortError') {
|
|
129
|
-
throw new Error(`Request timeout: Instagram OAuth server took too long to respond`);
|
|
130
|
-
}
|
|
131
|
-
throw new Error(`Network error: ${fetchError.message || 'Failed to connect to Instagram OAuth server'}`);
|
|
132
|
-
}
|
|
133
|
-
clearTimeout(timeoutId);
|
|
156
|
+
const response = await makeAuthenticatedRequest(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
body: JSON.stringify(jsonData)
|
|
159
|
+
});
|
|
134
160
|
console.log('๐ก Instagram OAuth response status:', response.status);
|
|
135
|
-
console.log('๐ก Instagram OAuth response headers:', response.headers);
|
|
136
161
|
if (!response.ok) {
|
|
137
162
|
const errorText = await response.text();
|
|
138
163
|
console.error('โ Instagram OAuth API error:', errorText);
|
|
@@ -165,31 +190,12 @@ export const initiateOAuth = async (platform, username, appName) => {
|
|
|
165
190
|
};
|
|
166
191
|
console.log(`๐ค Sending ${platform} OAuth request:`, jsonData);
|
|
167
192
|
|
|
168
|
-
// Make the request to get the OAuth URL
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
response = await fetch(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
175
|
-
method: 'POST',
|
|
176
|
-
headers: {
|
|
177
|
-
'Content-Type': 'application/json',
|
|
178
|
-
'User-Agent': 'OnairosReactNative/1.0'
|
|
179
|
-
},
|
|
180
|
-
body: JSON.stringify(jsonData),
|
|
181
|
-
signal: controller.signal
|
|
182
|
-
});
|
|
183
|
-
} catch (fetchError) {
|
|
184
|
-
clearTimeout(timeoutId);
|
|
185
|
-
if (fetchError.name === 'AbortError') {
|
|
186
|
-
throw new Error(`Request timeout: ${platform} OAuth server took too long to respond`);
|
|
187
|
-
}
|
|
188
|
-
throw new Error(`Network error: ${fetchError.message || 'Failed to connect to OAuth server'}`);
|
|
189
|
-
}
|
|
190
|
-
clearTimeout(timeoutId);
|
|
193
|
+
// Make the authenticated request to get the OAuth URL
|
|
194
|
+
const response = await makeAuthenticatedRequest(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
195
|
+
method: 'POST',
|
|
196
|
+
body: JSON.stringify(jsonData)
|
|
197
|
+
});
|
|
191
198
|
console.log(`๐ก ${platform} OAuth response status:`, response.status);
|
|
192
|
-
console.log(`๐ก ${platform} OAuth response headers:`, response.headers);
|
|
193
199
|
if (!response.ok) {
|
|
194
200
|
const errorText = await response.text();
|
|
195
201
|
console.error(`โ ${platform} OAuth API error:`, errorText);
|
|
@@ -792,91 +798,159 @@ export const updateGoogleClientIds = config => {
|
|
|
792
798
|
export const requestEmailVerification = async (email, testMode = false) => {
|
|
793
799
|
try {
|
|
794
800
|
console.log('๐ง Requesting email verification for:', email);
|
|
795
|
-
console.log('
|
|
801
|
+
console.log('๐งช Test mode:', testMode);
|
|
802
|
+
if (!email || !email.includes('@')) {
|
|
803
|
+
return {
|
|
804
|
+
success: false,
|
|
805
|
+
error: 'Valid email address is required'
|
|
806
|
+
};
|
|
807
|
+
}
|
|
796
808
|
|
|
797
|
-
//
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
})
|
|
806
|
-
});
|
|
807
|
-
const result = await response.json();
|
|
808
|
-
if (response.ok && result.success) {
|
|
809
|
-
console.log('โ
Email verification requested successfully');
|
|
810
|
-
const message = testMode ? 'Verification code sent to your email (testing mode: any code accepted)' : result.message || 'Verification code sent to your email';
|
|
809
|
+
// In test mode, always return success with mock request ID
|
|
810
|
+
if (testMode) {
|
|
811
|
+
console.log('๐งช Test mode: Always returning success with mock request ID');
|
|
812
|
+
const mockRequestId = 'test-request-' + Date.now();
|
|
813
|
+
|
|
814
|
+
// Store request info for tracking
|
|
815
|
+
await AsyncStorage.setItem('email_verification_request_id', mockRequestId);
|
|
816
|
+
await AsyncStorage.setItem('email_verification_request_email', email);
|
|
811
817
|
return {
|
|
812
818
|
success: true,
|
|
813
|
-
message
|
|
819
|
+
message: 'Email verification sent successfully (test mode)',
|
|
820
|
+
requestId: mockRequestId
|
|
814
821
|
};
|
|
815
|
-
}
|
|
816
|
-
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// Production mode: Make real API call with API key authentication
|
|
825
|
+
try {
|
|
826
|
+
// ๐ Ensure API key is initialized before making authenticated requests
|
|
827
|
+
await ensureApiKeyInitialized();
|
|
828
|
+
const response = await makeAuthenticatedRequest('/email/verification', {
|
|
829
|
+
method: 'POST',
|
|
830
|
+
body: JSON.stringify({
|
|
831
|
+
email,
|
|
832
|
+
action: 'request'
|
|
833
|
+
})
|
|
834
|
+
});
|
|
835
|
+
const result = await response.json();
|
|
836
|
+
console.log('๐ก Email verification API response:', result);
|
|
837
|
+
if (response.ok && result.success) {
|
|
838
|
+
console.log('โ
Email verification request sent');
|
|
839
|
+
|
|
840
|
+
// Store request info for tracking
|
|
841
|
+
const requestId = result.requestId || result.id || 'req-' + Date.now();
|
|
842
|
+
await AsyncStorage.setItem('email_verification_request_id', requestId);
|
|
843
|
+
await AsyncStorage.setItem('email_verification_request_email', email);
|
|
844
|
+
return {
|
|
845
|
+
success: true,
|
|
846
|
+
message: result.message || 'Email verification sent successfully',
|
|
847
|
+
requestId: requestId
|
|
848
|
+
};
|
|
849
|
+
} else {
|
|
850
|
+
console.error('โ Email verification request failed:', result.error);
|
|
851
|
+
return {
|
|
852
|
+
success: false,
|
|
853
|
+
error: result.error || 'Failed to send verification email'
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
} catch (apiError) {
|
|
857
|
+
console.error('โ Email verification API call failed:', apiError);
|
|
817
858
|
return {
|
|
818
859
|
success: false,
|
|
819
|
-
error:
|
|
860
|
+
error: 'Network error while sending verification email'
|
|
820
861
|
};
|
|
821
862
|
}
|
|
822
863
|
} catch (error) {
|
|
823
864
|
console.error('โ Email verification request error:', error);
|
|
824
865
|
return {
|
|
825
866
|
success: false,
|
|
826
|
-
error: error instanceof Error ? error.message : '
|
|
867
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
827
868
|
};
|
|
828
869
|
}
|
|
829
870
|
};
|
|
830
871
|
export const verifyEmailCode = async (email, code, testMode = false) => {
|
|
831
872
|
try {
|
|
832
873
|
console.log('๐ Verifying email code for:', email);
|
|
833
|
-
console.log('
|
|
874
|
+
console.log('๐ Code length:', code.length);
|
|
875
|
+
console.log('๐งช Test mode:', testMode);
|
|
876
|
+
if (!email || !email.includes('@')) {
|
|
877
|
+
return {
|
|
878
|
+
success: false,
|
|
879
|
+
error: 'Valid email address is required'
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
if (!code || code.length < 4) {
|
|
883
|
+
return {
|
|
884
|
+
success: false,
|
|
885
|
+
error: 'Valid verification code is required'
|
|
886
|
+
};
|
|
887
|
+
}
|
|
834
888
|
|
|
835
|
-
// In test mode,
|
|
889
|
+
// In test mode, always return success with mock JWT token
|
|
836
890
|
if (testMode) {
|
|
837
|
-
console.log('๐งช Test mode:
|
|
838
|
-
|
|
839
|
-
|
|
891
|
+
console.log('๐งช Test mode: Always returning success with mock JWT token');
|
|
892
|
+
const mockToken = 'test-jwt-token-' + Date.now();
|
|
893
|
+
|
|
894
|
+
// Store mock token for API requests
|
|
895
|
+
await AsyncStorage.setItem('email_verification_token', mockToken);
|
|
896
|
+
await AsyncStorage.setItem('onairos_jwt_token', mockToken);
|
|
897
|
+
await AsyncStorage.setItem('email_verification_email', email);
|
|
840
898
|
return {
|
|
841
899
|
success: true,
|
|
842
|
-
message: 'Email
|
|
843
|
-
existingUser:
|
|
900
|
+
message: 'Email verification successful (test mode)',
|
|
901
|
+
existingUser: false,
|
|
902
|
+
jwtToken: mockToken
|
|
844
903
|
};
|
|
845
904
|
}
|
|
846
905
|
|
|
847
|
-
// Production mode: Make real API call with
|
|
906
|
+
// Production mode: Make real API call with API key authentication
|
|
848
907
|
try {
|
|
849
|
-
|
|
908
|
+
// ๐ Ensure API key is initialized before making authenticated requests
|
|
909
|
+
await ensureApiKeyInitialized();
|
|
910
|
+
const response = await makeAuthenticatedRequest('/email/verification', {
|
|
850
911
|
method: 'POST',
|
|
851
|
-
headers: {
|
|
852
|
-
'Content-Type': 'application/json'
|
|
853
|
-
},
|
|
854
912
|
body: JSON.stringify({
|
|
855
913
|
email,
|
|
856
|
-
code
|
|
914
|
+
code,
|
|
915
|
+
action: 'verify'
|
|
857
916
|
})
|
|
858
917
|
});
|
|
859
918
|
const result = await response.json();
|
|
860
919
|
console.log('๐ก Email verification API response:', result);
|
|
861
920
|
if (response.ok && result.success) {
|
|
862
921
|
console.log('โ
Email verification successful');
|
|
922
|
+
|
|
923
|
+
// ๐ซ CRITICAL: Store JWT token from email verification response
|
|
924
|
+
const jwtToken = result.token || result.jwtToken || result.jwt || result.authToken;
|
|
925
|
+
if (jwtToken) {
|
|
926
|
+
console.log('๐ซ Storing JWT token from email verification response');
|
|
927
|
+
await AsyncStorage.setItem('email_verification_token', jwtToken);
|
|
928
|
+
await AsyncStorage.setItem('onairos_jwt_token', jwtToken);
|
|
929
|
+
await AsyncStorage.setItem('enoch_token', jwtToken);
|
|
930
|
+
await AsyncStorage.setItem('auth_token', jwtToken);
|
|
931
|
+
await AsyncStorage.setItem('email_verification_email', email);
|
|
932
|
+
await AsyncStorage.setItem('token_timestamp', Date.now().toString());
|
|
933
|
+
} else {
|
|
934
|
+
console.warn('โ ๏ธ No JWT token received from email verification API');
|
|
935
|
+
}
|
|
863
936
|
return {
|
|
864
937
|
success: true,
|
|
865
|
-
message: result.message || 'Email
|
|
866
|
-
existingUser: result.existingUser || false
|
|
938
|
+
message: result.message || 'Email verification successful',
|
|
939
|
+
existingUser: result.existingUser || false,
|
|
940
|
+
jwtToken: jwtToken
|
|
867
941
|
};
|
|
868
942
|
} else {
|
|
869
943
|
console.error('โ Email verification failed:', result.error);
|
|
870
944
|
return {
|
|
871
945
|
success: false,
|
|
872
|
-
error: result.error || '
|
|
946
|
+
error: result.error || 'Email verification failed'
|
|
873
947
|
};
|
|
874
948
|
}
|
|
875
949
|
} catch (apiError) {
|
|
876
950
|
console.error('โ Email verification API call failed:', apiError);
|
|
877
951
|
return {
|
|
878
952
|
success: false,
|
|
879
|
-
error: 'Network error during verification'
|
|
953
|
+
error: 'Network error during email verification'
|
|
880
954
|
};
|
|
881
955
|
}
|
|
882
956
|
} catch (error) {
|
|
@@ -902,13 +976,12 @@ export const checkEmailVerificationStatus = async (email, testMode = false) => {
|
|
|
902
976
|
};
|
|
903
977
|
}
|
|
904
978
|
|
|
905
|
-
// Production mode: Make real API call
|
|
979
|
+
// Production mode: Make real API call with API key authentication
|
|
906
980
|
try {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
}
|
|
981
|
+
// ๐ Ensure API key is initialized before making authenticated requests
|
|
982
|
+
await ensureApiKeyInitialized();
|
|
983
|
+
const response = await makeAuthenticatedRequest(`/email/verify/status/${encodeURIComponent(email)}`, {
|
|
984
|
+
method: 'GET'
|
|
912
985
|
});
|
|
913
986
|
const result = await response.json();
|
|
914
987
|
console.log('๐ก Email verification status API response:', result);
|
|
@@ -948,40 +1021,167 @@ export const checkEmailVerificationStatus = async (email, testMode = false) => {
|
|
|
948
1021
|
*/
|
|
949
1022
|
export const disconnectPlatform = async (platform, username) => {
|
|
950
1023
|
try {
|
|
951
|
-
console.log(
|
|
952
|
-
|
|
1024
|
+
console.log('๐ Disconnecting platform:', platform, 'for user:', username);
|
|
1025
|
+
if (!platform || !username) {
|
|
1026
|
+
return {
|
|
1027
|
+
success: false,
|
|
1028
|
+
error: 'Platform and username are required'
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// Make authenticated API call to disconnect platform
|
|
1033
|
+
const response = await makeAuthenticatedRequest('/revoke', {
|
|
1034
|
+
method: 'POST',
|
|
1035
|
+
body: JSON.stringify({
|
|
1036
|
+
platform,
|
|
1037
|
+
username
|
|
1038
|
+
})
|
|
1039
|
+
});
|
|
1040
|
+
const result = await response.json();
|
|
1041
|
+
console.log('๐ก Platform disconnect API response:', result);
|
|
1042
|
+
if (response.ok && result.success) {
|
|
1043
|
+
console.log('โ
Platform disconnected successfully');
|
|
1044
|
+
return {
|
|
1045
|
+
success: true,
|
|
1046
|
+
message: result.message || 'Platform disconnected successfully'
|
|
1047
|
+
};
|
|
1048
|
+
} else {
|
|
1049
|
+
console.error('โ Platform disconnect failed:', result.error);
|
|
1050
|
+
return {
|
|
1051
|
+
success: false,
|
|
1052
|
+
error: result.error || 'Failed to disconnect platform'
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
console.error('โ Platform disconnect error:', error);
|
|
1057
|
+
return {
|
|
1058
|
+
success: false,
|
|
1059
|
+
error: error instanceof Error ? error.message : 'Platform disconnect failed'
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* ๐ STORE PIN AFTER BIOMETRIC AUTHENTICATION
|
|
1066
|
+
* Send PIN separately to /store-pin/web endpoint after biometric Face ID verification
|
|
1067
|
+
*/
|
|
1068
|
+
export const storePinAfterBiometric = async (username, pin, jwtToken) => {
|
|
1069
|
+
try {
|
|
1070
|
+
console.log('๐ Storing PIN after biometric authentication for user:', username);
|
|
1071
|
+
console.log('๐ PIN length:', pin.length);
|
|
1072
|
+
console.log('๐ซ JWT token provided:', !!jwtToken);
|
|
1073
|
+
if (!username || !pin) {
|
|
1074
|
+
return {
|
|
1075
|
+
success: false,
|
|
1076
|
+
error: 'Username and PIN are required'
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
if (pin.length < 4) {
|
|
1080
|
+
return {
|
|
1081
|
+
success: false,
|
|
1082
|
+
error: 'PIN must be at least 4 digits'
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// Get JWT token from storage if not provided
|
|
1087
|
+
let authToken = jwtToken;
|
|
1088
|
+
if (!authToken) {
|
|
1089
|
+
authToken = (await AsyncStorage.getItem('onairos_jwt_token')) || (await AsyncStorage.getItem('enoch_token')) || (await AsyncStorage.getItem('auth_token')) || (await AsyncStorage.getItem('email_verification_token'));
|
|
1090
|
+
}
|
|
1091
|
+
if (!authToken) {
|
|
1092
|
+
console.warn('โ ๏ธ No JWT token available for PIN storage');
|
|
1093
|
+
return {
|
|
1094
|
+
success: false,
|
|
1095
|
+
error: 'No authentication token available'
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
console.log('๐ค Sending PIN to /store-pin/web endpoint');
|
|
1099
|
+
|
|
1100
|
+
// Make authenticated request to store PIN
|
|
1101
|
+
const response = await makeAuthenticatedRequest('/store-pin/web', {
|
|
953
1102
|
method: 'POST',
|
|
954
1103
|
headers: {
|
|
955
|
-
'
|
|
1104
|
+
'Authorization': `Bearer ${authToken}`
|
|
956
1105
|
},
|
|
957
1106
|
body: JSON.stringify({
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
// Capitalize platform name
|
|
961
|
-
username: username
|
|
962
|
-
}
|
|
1107
|
+
username,
|
|
1108
|
+
pin
|
|
963
1109
|
})
|
|
964
1110
|
});
|
|
1111
|
+
console.log('๐ก PIN storage response status:', response.status);
|
|
1112
|
+
if (!response.ok) {
|
|
1113
|
+
const errorText = await response.text();
|
|
1114
|
+
console.error('โ PIN storage failed:', errorText);
|
|
1115
|
+
return {
|
|
1116
|
+
success: false,
|
|
1117
|
+
error: `PIN storage failed: ${response.status} - ${errorText}`
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
965
1120
|
const result = await response.json();
|
|
966
|
-
|
|
967
|
-
|
|
1121
|
+
console.log('๐ฅ PIN storage response:', result);
|
|
1122
|
+
if (result.success) {
|
|
1123
|
+
console.log('โ
PIN stored successfully after biometric authentication');
|
|
1124
|
+
|
|
1125
|
+
// Store PIN locally for future use
|
|
1126
|
+
await AsyncStorage.setItem('user_pin_stored', 'true');
|
|
1127
|
+
await AsyncStorage.setItem('pin_storage_timestamp', Date.now().toString());
|
|
968
1128
|
return {
|
|
969
1129
|
success: true,
|
|
970
|
-
message: result.message ||
|
|
1130
|
+
message: result.message || 'PIN stored successfully'
|
|
971
1131
|
};
|
|
972
1132
|
} else {
|
|
973
|
-
console.error(
|
|
1133
|
+
console.error('โ PIN storage API returned error:', result.error);
|
|
974
1134
|
return {
|
|
975
1135
|
success: false,
|
|
976
|
-
error: result.error ||
|
|
1136
|
+
error: result.error || 'PIN storage failed'
|
|
977
1137
|
};
|
|
978
1138
|
}
|
|
979
1139
|
} catch (error) {
|
|
980
|
-
console.error(
|
|
1140
|
+
console.error('โ Error storing PIN after biometric authentication:', error);
|
|
981
1141
|
return {
|
|
982
1142
|
success: false,
|
|
983
|
-
error: error instanceof Error ? error.message : '
|
|
1143
|
+
error: error instanceof Error ? error.message : 'PIN storage failed'
|
|
984
1144
|
};
|
|
985
1145
|
}
|
|
986
1146
|
};
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* ๐ซ GET STORED JWT TOKEN
|
|
1150
|
+
* Helper function to retrieve stored JWT token from email verification or other sources
|
|
1151
|
+
*/
|
|
1152
|
+
export const getStoredJwtToken = async () => {
|
|
1153
|
+
try {
|
|
1154
|
+
console.log('๐ซ Retrieving stored JWT token...');
|
|
1155
|
+
|
|
1156
|
+
// Try different storage keys in order of preference
|
|
1157
|
+
const tokenSources = ['email_verification_token', 'onairos_jwt_token', 'enoch_token', 'auth_token'];
|
|
1158
|
+
for (const source of tokenSources) {
|
|
1159
|
+
const token = await AsyncStorage.getItem(source);
|
|
1160
|
+
if (token && token.length > 20) {
|
|
1161
|
+
console.log(`โ
JWT token found in ${source}:`, token.substring(0, 20) + '...');
|
|
1162
|
+
return token;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
console.warn('โ ๏ธ No JWT token found in storage');
|
|
1166
|
+
return null;
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
console.error('โ Error retrieving JWT token:', error);
|
|
1169
|
+
return null;
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* ๐ซ CLEAR STORED TOKENS
|
|
1175
|
+
* Helper function to clear all stored tokens (useful for logout)
|
|
1176
|
+
*/
|
|
1177
|
+
export const clearStoredTokens = async () => {
|
|
1178
|
+
try {
|
|
1179
|
+
console.log('๐งน Clearing all stored tokens...');
|
|
1180
|
+
const tokenKeys = ['email_verification_token', 'onairos_jwt_token', 'enoch_token', 'auth_token', 'email_verification_email', 'email_verification_request_id', 'email_verification_request_email', 'token_timestamp', 'user_pin_stored', 'pin_storage_timestamp'];
|
|
1181
|
+
await Promise.all(tokenKeys.map(key => AsyncStorage.removeItem(key)));
|
|
1182
|
+
console.log('โ
All tokens cleared successfully');
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
console.error('โ Error clearing tokens:', error);
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
987
1187
|
//# sourceMappingURL=platformAuthService.js.map
|