@onairos/react-native 3.0.75 → 3.1.0

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 (43) hide show
  1. package/lib/commonjs/components/EmailVerificationModal.js +7 -5
  2. package/lib/commonjs/components/EmailVerificationModal.js.map +1 -1
  3. package/lib/commonjs/index.js +0 -6
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/commonjs/services/apiKeyService.js +278 -27
  6. package/lib/commonjs/services/apiKeyService.js.map +1 -1
  7. package/lib/commonjs/services/platformAuthService.js +123 -301
  8. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  9. package/lib/commonjs/utils/onairosApi.js +143 -71
  10. package/lib/commonjs/utils/onairosApi.js.map +1 -1
  11. package/lib/commonjs/utils/secureStorage.js +123 -1
  12. package/lib/commonjs/utils/secureStorage.js.map +1 -1
  13. package/lib/module/components/EmailVerificationModal.js +7 -5
  14. package/lib/module/components/EmailVerificationModal.js.map +1 -1
  15. package/lib/module/index.js +3 -1
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/services/apiKeyService.js +264 -22
  18. package/lib/module/services/apiKeyService.js.map +1 -1
  19. package/lib/module/services/platformAuthService.js +120 -297
  20. package/lib/module/services/platformAuthService.js.map +1 -1
  21. package/lib/module/utils/onairosApi.js +139 -70
  22. package/lib/module/utils/onairosApi.js.map +1 -1
  23. package/lib/module/utils/secureStorage.js +116 -0
  24. package/lib/module/utils/secureStorage.js.map +1 -1
  25. package/lib/typescript/components/EmailVerificationModal.d.ts.map +1 -1
  26. package/lib/typescript/index.d.ts +1 -1
  27. package/lib/typescript/index.d.ts.map +1 -1
  28. package/lib/typescript/services/apiKeyService.d.ts +50 -2
  29. package/lib/typescript/services/apiKeyService.d.ts.map +1 -1
  30. package/lib/typescript/services/platformAuthService.d.ts +29 -14
  31. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  32. package/lib/typescript/utils/onairosApi.d.ts +24 -10
  33. package/lib/typescript/utils/onairosApi.d.ts.map +1 -1
  34. package/lib/typescript/utils/secureStorage.d.ts +31 -0
  35. package/lib/typescript/utils/secureStorage.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/components/EmailVerificationModal.tsx +9 -5
  38. package/src/index.ts +1 -1
  39. package/src/services/apiKeyService.ts +282 -18
  40. package/src/services/platformAuthService.ts +211 -424
  41. package/src/types/index.d.ts +6 -5
  42. package/src/utils/onairosApi.ts +151 -74
  43. package/src/utils/secureStorage.ts +122 -0
@@ -3,74 +3,39 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.verifyEmailCode = exports.updateGoogleClientIds = exports.testApiConnectivity = exports.storePinAfterBiometric = exports.requestEmailVerification = exports.refreshYouTubeTokens = exports.refreshGoogleTokens = exports.isOAuthCallback = exports.initiateOAuth = exports.initiateNativeAuth = exports.initializePlatformAuthService = exports.hasNativeSDK = exports.handleOAuthCallbackUrl = exports.handleOAuthCallback = exports.getStoredJwtToken = exports.getPlatformColor = exports.getAuthEndpoint = exports.disconnectPlatform = exports.clearStoredTokens = exports.checkEmailVerificationStatus = void 0;
6
+ exports.verifyEmailCode = exports.updateGoogleClientIds = exports.testApiConnectivity = exports.storePIN = exports.requestEmailVerification = exports.refreshYouTubeTokens = exports.refreshGoogleTokens = exports.isOAuthCallback = exports.initiateOAuth = exports.initiateNativeAuth = exports.initializePlatformAuthService = exports.hasNativeSDK = exports.handleOAuthCallbackUrl = exports.handleOAuthCallback = exports.getStoredJwtToken = exports.getPlatformColor = exports.getAuthEndpoint = exports.disconnectPlatform = exports.clearStoredTokens = exports.checkEmailVerificationStatus = void 0;
7
7
  var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
8
8
  var _apiKeyService = require("./apiKeyService");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
- // 🔑 CRITICAL: Initialize API key service for authentication
12
- let isApiKeyInitialized = false;
10
+ // 🔑 CRITICAL: Use two-tier authentication system
11
+ // - Developer API key for email verification requests
12
+ // - JWT tokens for user-authenticated requests after email verification
13
13
 
14
14
  /**
15
- * Initialize the API key service with the admin key for testing
16
- * This ensures all API requests include proper authentication headers
15
+ * Initialize the platform auth service
16
+ * This service now uses the two-tier authentication system
17
17
  */
18
18
  const initializePlatformAuthService = async () => {
19
- if (isApiKeyInitialized) {
20
- console.log('🔑 API key service already initialized');
21
- return;
22
- }
23
19
  try {
24
- // Import the initialization function
25
- const {
26
- initializeApiKey,
27
- ADMIN_API_KEY,
28
- getApiConfig
29
- } = await Promise.resolve().then(() => _interopRequireWildcard(require('./apiKeyService')));
30
-
31
- // Check if there's already an app initialization
32
- const existingConfig = getApiConfig();
20
+ // Check if app is already initialized with API key
21
+ const existingConfig = (0, _apiKeyService.getApiConfig)();
33
22
  if (existingConfig && existingConfig.apiKey) {
34
- console.log('🔑 App already initialized with API key, using existing configuration');
35
- // Use the existing app's configuration instead of overriding
36
- isApiKeyInitialized = true;
37
- console.log(`✅ Platform auth service using existing app configuration (${existingConfig.environment})`);
23
+ console.log('🔑 Platform auth service using existing app configuration');
24
+ console.log(`✅ Environment: ${existingConfig.environment}`);
38
25
  return;
39
26
  }
40
27
 
41
- // Only initialize with admin key if no app initialization exists
42
- const environment = __DEV__ ? 'development' : 'production';
43
- console.log('🔑 No app initialization found, initializing platform auth service with admin key');
44
- console.log('🔑 Environment:', environment);
45
-
46
- // Initialize with admin key as fallback
47
- await initializeApiKey({
48
- apiKey: ADMIN_API_KEY,
49
- // 'OnairosIsAUnicorn2025'
50
- environment: environment,
51
- enableLogging: true,
52
- timeout: 30000
53
- });
54
- isApiKeyInitialized = true;
55
- console.log(`✅ Platform auth service initialized with admin key (${environment})`);
28
+ // If no app initialization, we can't proceed
29
+ console.error('❌ Platform auth service requires app-level API key initialization');
30
+ throw new Error('Platform auth service requires app-level API key initialization. Please call initializeApiKey() first.');
56
31
  } catch (error) {
57
32
  console.error('❌ Failed to initialize platform auth service:', error);
58
33
  throw error;
59
34
  }
60
35
  };
61
36
 
62
- /**
63
- * Ensure API key is initialized before making authenticated requests
64
- */
65
- exports.initializePlatformAuthService = initializePlatformAuthService;
66
- const ensureApiKeyInitialized = async () => {
67
- if (!isApiKeyInitialized) {
68
- console.log('🔑 API key not initialized, initializing now...');
69
- await initializePlatformAuthService();
70
- }
71
- };
72
-
73
37
  // Configuration for each platform's authentication
38
+ exports.initializePlatformAuthService = initializePlatformAuthService;
74
39
  let PLATFORM_AUTH_CONFIG = {
75
40
  instagram: {
76
41
  hasNativeSDK: false,
@@ -180,7 +145,7 @@ const initiateOAuth = async (platform, username, appName) => {
180
145
  }
181
146
  };
182
147
  console.log('📤 Sending Instagram OAuth request:', jsonData);
183
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
148
+ const response = await (0, _apiKeyService.makeDeveloperRequest)(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
184
149
  method: 'POST',
185
150
  body: JSON.stringify(jsonData)
186
151
  });
@@ -218,7 +183,7 @@ const initiateOAuth = async (platform, username, appName) => {
218
183
  console.log(`📤 Sending ${platform} OAuth request:`, jsonData);
219
184
 
220
185
  // Make the authenticated request to get the OAuth URL
221
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
186
+ const response = await (0, _apiKeyService.makeDeveloperRequest)(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
222
187
  method: 'POST',
223
188
  body: JSON.stringify(jsonData)
224
189
  });
@@ -827,360 +792,217 @@ const updateGoogleClientIds = config => {
827
792
  };
828
793
 
829
794
  /**
830
- * 📧 EMAIL VERIFICATION FUNCTIONS
831
- * Using the correct Onairos email verification endpoints
795
+ * Request email verification using developer API key
796
+ * @param email Email address to verify
797
+ * @param testMode Whether to use test mode
798
+ * @returns Promise with verification result
832
799
  */
833
800
  exports.updateGoogleClientIds = updateGoogleClientIds;
834
801
  const requestEmailVerification = async (email, testMode = false) => {
835
802
  try {
836
803
  console.log('📧 Requesting email verification for:', email);
837
- console.log('🧪 Test mode:', testMode);
838
- if (!email || !email.includes('@')) {
839
- return {
840
- success: false,
841
- error: 'Valid email address is required'
842
- };
843
- }
844
-
845
- // In test mode, always return success with mock request ID
846
- if (testMode) {
847
- console.log('🧪 Test mode: Always returning success with mock request ID');
848
- const mockRequestId = 'test-request-' + Date.now();
849
-
850
- // Store request info for tracking
851
- await _asyncStorage.default.setItem('email_verification_request_id', mockRequestId);
852
- await _asyncStorage.default.setItem('email_verification_request_email', email);
804
+ const response = await (0, _apiKeyService.makeDeveloperRequest)('/email/verification', {
805
+ method: 'POST',
806
+ body: JSON.stringify({
807
+ email,
808
+ action: 'request',
809
+ testMode
810
+ })
811
+ });
812
+ const data = await response.json();
813
+ if (response.ok && data.success) {
814
+ console.log(' Email verification requested successfully');
853
815
  return {
854
816
  success: true,
855
- message: 'Email verification sent successfully (test mode)',
856
- requestId: mockRequestId
817
+ message: data.message || 'Verification code sent to your email'
857
818
  };
858
- }
859
-
860
- // Production mode: Make real API call with API key authentication
861
- try {
862
- // 🔑 Ensure API key is initialized before making authenticated requests
863
- await ensureApiKeyInitialized();
864
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)('/email/verification', {
865
- method: 'POST',
866
- body: JSON.stringify({
867
- email,
868
- action: 'request'
869
- })
870
- });
871
- const result = await response.json();
872
- console.log('📡 Email verification API response:', result);
873
- if (response.ok && result.success) {
874
- console.log('✅ Email verification request sent');
875
-
876
- // Store request info for tracking
877
- const requestId = result.requestId || result.id || 'req-' + Date.now();
878
- await _asyncStorage.default.setItem('email_verification_request_id', requestId);
879
- await _asyncStorage.default.setItem('email_verification_request_email', email);
880
- return {
881
- success: true,
882
- message: result.message || 'Email verification sent successfully',
883
- requestId: requestId
884
- };
885
- } else {
886
- console.error('❌ Email verification request failed:', result.error);
887
- return {
888
- success: false,
889
- error: result.error || 'Failed to send verification email'
890
- };
891
- }
892
- } catch (apiError) {
893
- console.error('❌ Email verification API call failed:', apiError);
819
+ } else {
820
+ console.error('❌ Email verification request failed:', data.error);
894
821
  return {
895
822
  success: false,
896
- error: 'Network error while sending verification email'
823
+ error: data.error || 'Failed to send verification code'
897
824
  };
898
825
  }
899
826
  } catch (error) {
900
- console.error('❌ Email verification request error:', error);
827
+ console.error('❌ Error requesting email verification:', error);
901
828
  return {
902
829
  success: false,
903
- error: error instanceof Error ? error.message : 'Unknown error'
830
+ error: error instanceof Error ? error.message : 'Network error'
904
831
  };
905
832
  }
906
833
  };
834
+
835
+ /**
836
+ * Verify email code and store JWT token
837
+ * @param email Email address
838
+ * @param code Verification code
839
+ * @param testMode Whether to use test mode
840
+ * @returns Promise with verification result and JWT token
841
+ */
907
842
  exports.requestEmailVerification = requestEmailVerification;
908
843
  const verifyEmailCode = async (email, code, testMode = false) => {
909
844
  try {
910
845
  console.log('🔍 Verifying email code for:', email);
911
- console.log('🔑 Code length:', code.length);
912
- console.log('🧪 Test mode:', testMode);
913
- if (!email || !email.includes('@')) {
914
- return {
915
- success: false,
916
- error: 'Valid email address is required'
917
- };
918
- }
919
- if (!code || code.length < 4) {
920
- return {
921
- success: false,
922
- error: 'Valid verification code is required'
923
- };
924
- }
925
-
926
- // In test mode, always return success with mock JWT token
927
- if (testMode) {
928
- console.log('🧪 Test mode: Always returning success with mock JWT token');
929
- const mockToken = 'test-jwt-token-' + Date.now();
930
-
931
- // Store mock token for API requests
932
- await _asyncStorage.default.setItem('email_verification_token', mockToken);
933
- await _asyncStorage.default.setItem('onairos_jwt_token', mockToken);
934
- await _asyncStorage.default.setItem('email_verification_email', email);
846
+ const response = await (0, _apiKeyService.makeDeveloperRequest)('/email/verification', {
847
+ method: 'POST',
848
+ body: JSON.stringify({
849
+ email,
850
+ action: 'verify',
851
+ code,
852
+ testMode
853
+ })
854
+ });
855
+ const data = await response.json();
856
+ if (response.ok && data.success) {
857
+ console.log(' Email verification successful');
858
+
859
+ // Store JWT token if received
860
+ if (data.token || data.jwtToken) {
861
+ const jwtToken = data.token || data.jwtToken;
862
+ await (0, _apiKeyService.storeJWT)(jwtToken);
863
+ console.log('🎫 JWT token stored successfully');
864
+ }
935
865
  return {
936
866
  success: true,
937
- message: 'Email verification successful (test mode)',
938
- existingUser: false,
939
- jwtToken: mockToken
867
+ message: data.message || 'Email verified successfully',
868
+ existingUser: data.existingUser || false,
869
+ token: data.token || data.jwtToken
940
870
  };
941
- }
942
-
943
- // Production mode: Make real API call with API key authentication
944
- try {
945
- // 🔑 Ensure API key is initialized before making authenticated requests
946
- await ensureApiKeyInitialized();
947
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)('/email/verification', {
948
- method: 'POST',
949
- body: JSON.stringify({
950
- email,
951
- code,
952
- action: 'verify'
953
- })
954
- });
955
- const result = await response.json();
956
- console.log('📡 Email verification API response:', result);
957
- if (response.ok && result.success) {
958
- console.log('✅ Email verification successful');
959
-
960
- // 🎫 CRITICAL: Store JWT token from email verification response
961
- const jwtToken = result.token || result.jwtToken || result.jwt || result.authToken;
962
- if (jwtToken) {
963
- console.log('🎫 Storing JWT token from email verification response');
964
- await _asyncStorage.default.setItem('email_verification_token', jwtToken);
965
- await _asyncStorage.default.setItem('onairos_jwt_token', jwtToken);
966
- await _asyncStorage.default.setItem('enoch_token', jwtToken);
967
- await _asyncStorage.default.setItem('auth_token', jwtToken);
968
- await _asyncStorage.default.setItem('email_verification_email', email);
969
- await _asyncStorage.default.setItem('token_timestamp', Date.now().toString());
970
- } else {
971
- console.warn('⚠️ No JWT token received from email verification API');
972
- }
973
- return {
974
- success: true,
975
- message: result.message || 'Email verification successful',
976
- existingUser: result.existingUser || false,
977
- jwtToken: jwtToken
978
- };
979
- } else {
980
- console.error('❌ Email verification failed:', result.error);
981
- return {
982
- success: false,
983
- error: result.error || 'Email verification failed'
984
- };
985
- }
986
- } catch (apiError) {
987
- console.error('❌ Email verification API call failed:', apiError);
871
+ } else {
872
+ console.error('❌ Email verification failed:', data.error);
988
873
  return {
989
874
  success: false,
990
- error: 'Network error during email verification'
875
+ error: data.error || 'Invalid verification code'
991
876
  };
992
877
  }
993
878
  } catch (error) {
994
- console.error('❌ Email verification error:', error);
879
+ console.error('❌ Error verifying email code:', error);
995
880
  return {
996
881
  success: false,
997
- error: error instanceof Error ? error.message : 'Unknown error'
882
+ error: error instanceof Error ? error.message : 'Network error'
998
883
  };
999
884
  }
1000
885
  };
886
+
887
+ /**
888
+ * Check email verification status
889
+ * @param email Email address
890
+ * @param testMode Whether to use test mode
891
+ * @returns Promise with status result
892
+ */
1001
893
  exports.verifyEmailCode = verifyEmailCode;
1002
894
  const checkEmailVerificationStatus = async (email, testMode = false) => {
1003
895
  try {
1004
896
  console.log('🔍 Checking email verification status for:', email);
1005
- console.log('🔍 Test mode:', testMode);
1006
-
1007
- // In test mode, always return no pending verification
1008
- if (testMode) {
1009
- console.log('🧪 Test mode: Always returning no pending verification');
897
+ const response = await (0, _apiKeyService.makeDeveloperRequest)('/email/verification/status', {
898
+ method: 'POST',
899
+ body: JSON.stringify({
900
+ email,
901
+ testMode
902
+ })
903
+ });
904
+ const data = await response.json();
905
+ if (response.ok && data.success) {
1010
906
  return {
1011
907
  success: true,
1012
- isPending: false,
1013
- message: 'Status retrieved successfully (test mode)'
908
+ isPending: data.isPending || false
1014
909
  };
1015
- }
1016
-
1017
- // Production mode: Make real API call with API key authentication
1018
- try {
1019
- // 🔑 Ensure API key is initialized before making authenticated requests
1020
- await ensureApiKeyInitialized();
1021
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)(`/email/verify/status/${encodeURIComponent(email)}`, {
1022
- method: 'GET'
1023
- });
1024
- const result = await response.json();
1025
- console.log('📡 Email verification status API response:', result);
1026
- if (response.ok && result.success) {
1027
- console.log('✅ Email verification status retrieved');
1028
- return {
1029
- success: true,
1030
- isPending: result.isPending || false,
1031
- message: result.message || 'Status retrieved successfully'
1032
- };
1033
- } else {
1034
- console.error('❌ Email verification status failed:', result.error);
1035
- return {
1036
- success: false,
1037
- error: result.error || 'Failed to check verification status'
1038
- };
1039
- }
1040
- } catch (apiError) {
1041
- console.error('❌ Email verification status API call failed:', apiError);
910
+ } else {
1042
911
  return {
1043
912
  success: false,
1044
- error: 'Network error while checking status'
913
+ error: data.error || 'Failed to check verification status'
1045
914
  };
1046
915
  }
1047
916
  } catch (error) {
1048
- console.error('❌ Email verification status error:', error);
917
+ console.error('❌ Error checking email verification status:', error);
1049
918
  return {
1050
919
  success: false,
1051
- error: error instanceof Error ? error.message : 'Unknown error'
920
+ error: error instanceof Error ? error.message : 'Network error'
1052
921
  };
1053
922
  }
1054
923
  };
1055
924
 
1056
925
  /**
1057
- * 🔌 UNIVERSAL PLATFORM DISCONNECTION
1058
- * Backend confirmed this endpoint is fully implemented
926
+ * Disconnect a platform (uses developer API key)
927
+ * @param platform Platform to disconnect
928
+ * @param username Username associated with the platform
929
+ * @returns Promise with disconnect result
1059
930
  */
1060
931
  exports.checkEmailVerificationStatus = checkEmailVerificationStatus;
1061
932
  const disconnectPlatform = async (platform, username) => {
1062
933
  try {
1063
934
  console.log('🔌 Disconnecting platform:', platform, 'for user:', username);
1064
- if (!platform || !username) {
1065
- return {
1066
- success: false,
1067
- error: 'Platform and username are required'
1068
- };
1069
- }
1070
935
 
1071
936
  // Make authenticated API call to disconnect platform
1072
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)('/revoke', {
937
+ const response = await (0, _apiKeyService.makeDeveloperRequest)('/revoke', {
1073
938
  method: 'POST',
1074
939
  body: JSON.stringify({
1075
940
  platform,
1076
941
  username
1077
942
  })
1078
943
  });
1079
- const result = await response.json();
1080
- console.log('📡 Platform disconnect API response:', result);
1081
- if (response.ok && result.success) {
1082
- console.log('✅ Platform disconnected successfully');
944
+ const data = await response.json();
945
+ if (response.ok && data.success) {
946
+ console.log(`✅ ${platform} disconnected successfully`);
1083
947
  return {
1084
- success: true,
1085
- message: result.message || 'Platform disconnected successfully'
948
+ success: true
1086
949
  };
1087
950
  } else {
1088
- console.error('❌ Platform disconnect failed:', result.error);
951
+ console.error(`❌ Failed to disconnect ${platform}:`, data.error);
1089
952
  return {
1090
953
  success: false,
1091
- error: result.error || 'Failed to disconnect platform'
954
+ error: data.error || 'Failed to disconnect platform'
1092
955
  };
1093
956
  }
1094
957
  } catch (error) {
1095
- console.error('❌ Platform disconnect error:', error);
958
+ console.error(`❌ Error disconnecting ${platform}:`, error);
1096
959
  return {
1097
960
  success: false,
1098
- error: error instanceof Error ? error.message : 'Platform disconnect failed'
961
+ error: error instanceof Error ? error.message : 'Network error'
1099
962
  };
1100
963
  }
1101
964
  };
1102
965
 
1103
966
  /**
1104
- * 🔐 STORE PIN AFTER BIOMETRIC AUTHENTICATION
1105
- * Send PIN separately to /store-pin/web endpoint after biometric Face ID verification
967
+ * Store PIN for user (uses developer API key for now, should be JWT in future)
968
+ * @param username Username
969
+ * @param pin User PIN
970
+ * @returns Promise with result
1106
971
  */
1107
972
  exports.disconnectPlatform = disconnectPlatform;
1108
- const storePinAfterBiometric = async (username, pin, jwtToken) => {
973
+ const storePIN = async (username, pin) => {
1109
974
  try {
1110
- console.log('🔐 Storing PIN after biometric authentication for user:', username);
1111
- console.log('🔑 PIN length:', pin.length);
1112
- console.log('🎫 JWT token provided:', !!jwtToken);
1113
- if (!username || !pin) {
1114
- return {
1115
- success: false,
1116
- error: 'Username and PIN are required'
1117
- };
1118
- }
1119
- if (pin.length < 4) {
1120
- return {
1121
- success: false,
1122
- error: 'PIN must be at least 4 digits'
1123
- };
1124
- }
1125
-
1126
- // Get JWT token from storage if not provided
1127
- let authToken = jwtToken;
1128
- if (!authToken) {
1129
- authToken = (await _asyncStorage.default.getItem('onairos_jwt_token')) || (await _asyncStorage.default.getItem('enoch_token')) || (await _asyncStorage.default.getItem('auth_token')) || (await _asyncStorage.default.getItem('email_verification_token'));
1130
- }
1131
- if (!authToken) {
1132
- console.warn('⚠️ No JWT token available for PIN storage');
1133
- return {
1134
- success: false,
1135
- error: 'No authentication token available'
1136
- };
1137
- }
1138
- console.log('📤 Sending PIN to /store-pin/web endpoint');
975
+ console.log('🔐 Storing PIN for user:', username);
1139
976
 
1140
977
  // Make authenticated request to store PIN
1141
- const response = await (0, _apiKeyService.makeAuthenticatedRequest)('/store-pin/web', {
978
+ const response = await (0, _apiKeyService.makeDeveloperRequest)('/store-pin/web', {
1142
979
  method: 'POST',
1143
980
  headers: {
1144
- 'Authorization': `Bearer ${authToken}`
981
+ 'Content-Type': 'application/json'
1145
982
  },
1146
983
  body: JSON.stringify({
1147
984
  username,
1148
985
  pin
1149
986
  })
1150
987
  });
1151
- console.log('📡 PIN storage response status:', response.status);
1152
- if (!response.ok) {
1153
- const errorText = await response.text();
1154
- console.error('❌ PIN storage failed:', errorText);
1155
- return {
1156
- success: false,
1157
- error: `PIN storage failed: ${response.status} - ${errorText}`
1158
- };
1159
- }
1160
- const result = await response.json();
1161
- console.log('📥 PIN storage response:', result);
1162
- if (result.success) {
1163
- console.log('✅ PIN stored successfully after biometric authentication');
1164
-
1165
- // Store PIN locally for future use
1166
- await _asyncStorage.default.setItem('user_pin_stored', 'true');
1167
- await _asyncStorage.default.setItem('pin_storage_timestamp', Date.now().toString());
988
+ const data = await response.json();
989
+ if (response.ok && data.success) {
990
+ console.log('✅ PIN stored successfully');
1168
991
  return {
1169
- success: true,
1170
- message: result.message || 'PIN stored successfully'
992
+ success: true
1171
993
  };
1172
994
  } else {
1173
- console.error('❌ PIN storage API returned error:', result.error);
995
+ console.error('❌ Failed to store PIN:', data.error);
1174
996
  return {
1175
997
  success: false,
1176
- error: result.error || 'PIN storage failed'
998
+ error: data.error || 'Failed to store PIN'
1177
999
  };
1178
1000
  }
1179
1001
  } catch (error) {
1180
- console.error('❌ Error storing PIN after biometric authentication:', error);
1002
+ console.error('❌ Error storing PIN:', error);
1181
1003
  return {
1182
1004
  success: false,
1183
- error: error instanceof Error ? error.message : 'PIN storage failed'
1005
+ error: error instanceof Error ? error.message : 'Network error'
1184
1006
  };
1185
1007
  }
1186
1008
  };
@@ -1189,7 +1011,7 @@ const storePinAfterBiometric = async (username, pin, jwtToken) => {
1189
1011
  * 🎫 GET STORED JWT TOKEN
1190
1012
  * Helper function to retrieve stored JWT token from email verification or other sources
1191
1013
  */
1192
- exports.storePinAfterBiometric = storePinAfterBiometric;
1014
+ exports.storePIN = storePIN;
1193
1015
  const getStoredJwtToken = async () => {
1194
1016
  try {
1195
1017
  console.log('🎫 Retrieving stored JWT token...');