@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.
Files changed (65) hide show
  1. package/lib/commonjs/components/Onairos.js +294 -155
  2. package/lib/commonjs/components/Onairos.js.map +1 -1
  3. package/lib/commonjs/components/OnairosButton.js +1 -1
  4. package/lib/commonjs/components/OnairosButton.js.map +1 -1
  5. package/lib/commonjs/components/UniversalOnboarding.js +6 -6
  6. package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
  7. package/lib/commonjs/components/onboarding/OAuthWebView.js +188 -52
  8. package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
  9. package/lib/commonjs/index.js +25 -440
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/services/apiKeyService.js +404 -0
  12. package/lib/commonjs/services/apiKeyService.js.map +1 -0
  13. package/lib/commonjs/services/platformAuthService.js +318 -113
  14. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  15. package/lib/commonjs/types/index.js +4 -0
  16. package/lib/commonjs/types.js +12 -0
  17. package/lib/commonjs/types.js.map +1 -1
  18. package/lib/commonjs/utils/programmaticFlow.js +117 -0
  19. package/lib/commonjs/utils/programmaticFlow.js.map +1 -0
  20. package/lib/module/components/Onairos.js +297 -158
  21. package/lib/module/components/Onairos.js.map +1 -1
  22. package/lib/module/components/OnairosButton.js +1 -1
  23. package/lib/module/components/OnairosButton.js.map +1 -1
  24. package/lib/module/components/UniversalOnboarding.js +6 -6
  25. package/lib/module/components/UniversalOnboarding.js.map +1 -1
  26. package/lib/module/components/onboarding/OAuthWebView.js +188 -52
  27. package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
  28. package/lib/module/index.js +17 -61
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/services/apiKeyService.js +389 -0
  31. package/lib/module/services/apiKeyService.js.map +1 -0
  32. package/lib/module/services/platformAuthService.js +311 -111
  33. package/lib/module/services/platformAuthService.js.map +1 -1
  34. package/lib/module/types/index.js +1 -1
  35. package/lib/module/types.js +8 -0
  36. package/lib/module/types.js.map +1 -1
  37. package/lib/module/utils/programmaticFlow.js +111 -0
  38. package/lib/module/utils/programmaticFlow.js.map +1 -0
  39. package/lib/typescript/components/Onairos.d.ts +2 -29
  40. package/lib/typescript/components/Onairos.d.ts.map +1 -1
  41. package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
  42. package/lib/typescript/index.d.ts +10 -39
  43. package/lib/typescript/index.d.ts.map +1 -1
  44. package/lib/typescript/services/apiKeyService.d.ts +66 -0
  45. package/lib/typescript/services/apiKeyService.d.ts.map +1 -0
  46. package/lib/typescript/services/platformAuthService.d.ts +26 -0
  47. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  48. package/lib/typescript/types/index.d.ts +144 -78
  49. package/lib/typescript/types/index.d.ts.map +1 -1
  50. package/lib/typescript/types.d.ts +92 -3
  51. package/lib/typescript/types.d.ts.map +1 -1
  52. package/lib/typescript/utils/programmaticFlow.d.ts +23 -0
  53. package/lib/typescript/utils/programmaticFlow.d.ts.map +1 -0
  54. package/package.json +1 -1
  55. package/src/components/Onairos.tsx +330 -207
  56. package/src/components/OnairosButton.tsx +1 -1
  57. package/src/components/UniversalOnboarding.tsx +6 -6
  58. package/src/components/onboarding/OAuthWebView.tsx +236 -71
  59. package/src/index.ts +25 -115
  60. package/src/services/apiKeyService.ts +401 -0
  61. package/src/services/platformAuthService.ts +363 -126
  62. package/src/types/index.d.ts +110 -0
  63. package/src/types/index.ts +148 -74
  64. package/src/types.ts +99 -3
  65. 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
- // Define types for platform auth configuration
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: 'https://api2.onairos.uk/instagram/authorize',
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: 'https://api2.onairos.uk/youtube/authorize',
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: 'https://api2.onairos.uk/reddit/authorize',
70
+ authEndpoint: '/reddit/authorize',
27
71
  color: '#FF4500'
28
72
  },
29
73
  pinterest: {
30
74
  hasNativeSDK: false,
31
- authEndpoint: 'https://api2.onairos.uk/pinterest/authorize',
75
+ authEndpoint: '/pinterest/authorize',
32
76
  color: '#E60023'
33
77
  },
34
78
  email: {
35
79
  hasNativeSDK: false,
36
- authEndpoint: 'https://api2.onairos.uk/gmail/authorize',
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 controller = new AbortController();
113
- const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
114
-
115
- let response;
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 with enhanced error handling
169
- const controller = new AbortController();
170
- const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
171
-
172
- let response;
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('๐Ÿ” Test mode:', testMode);
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
- // Use the correct endpoint: /email/verify
798
- const response = await fetch('https://api2.onairos.uk/email/verify', {
799
- method: 'POST',
800
- headers: {
801
- 'Content-Type': 'application/json'
802
- },
803
- body: JSON.stringify({
804
- email
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
- } else {
816
- console.error('โŒ Email verification request failed:', result.error);
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: result.error || 'Failed to send verification code'
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 : 'Network error'
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('๐Ÿ” Test mode:', testMode);
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, accept any code
889
+ // In test mode, always return success with mock JWT token
836
890
  if (testMode) {
837
- console.log('๐Ÿงช Test mode: All codes will pass through');
838
- // Simulate 30% chance of existing user in test mode
839
- const simulateExistingUser = Math.random() < 0.3;
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 verified successfully (test mode: all codes accepted)',
843
- existingUser: simulateExistingUser
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 proper validation
906
+ // Production mode: Make real API call with API key authentication
848
907
  try {
849
- const response = await fetch('https://api2.onairos.uk/email/verify/confirm', {
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 verified successfully',
866
- existingUser: result.existingUser || false // Backend should return this flag
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 || 'Invalid verification code'
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
- const response = await fetch(`https://api2.onairos.uk/email/verify/status/${encodeURIComponent(email)}`, {
908
- method: 'GET',
909
- headers: {
910
- 'Content-Type': 'application/json'
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(`๐Ÿ”Œ Disconnecting ${platform} for user:`, username);
952
- const response = await fetch('https://api2.onairos.uk/revoke', {
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
- 'Content-Type': 'application/json'
1104
+ 'Authorization': `Bearer ${authToken}`
956
1105
  },
957
1106
  body: JSON.stringify({
958
- Info: {
959
- connection: platform.charAt(0).toUpperCase() + platform.slice(1),
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
- if (response.ok && result.success) {
967
- console.log(`โœ… ${platform} disconnected successfully`);
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 || `${platform} disconnected successfully`
1130
+ message: result.message || 'PIN stored successfully'
971
1131
  };
972
1132
  } else {
973
- console.error(`โŒ ${platform} disconnection failed:`, result.error);
1133
+ console.error('โŒ PIN storage API returned error:', result.error);
974
1134
  return {
975
1135
  success: false,
976
- error: result.error || `Failed to disconnect ${platform}`
1136
+ error: result.error || 'PIN storage failed'
977
1137
  };
978
1138
  }
979
1139
  } catch (error) {
980
- console.error(`โŒ ${platform} disconnection error:`, 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 : 'Network error'
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