@onairos/react-native 3.0.74 → 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.
- package/lib/commonjs/components/EmailVerificationModal.js +7 -5
- package/lib/commonjs/components/EmailVerificationModal.js.map +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +10 -1
- package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
- package/lib/commonjs/index.js +0 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/apiKeyService.js +278 -27
- package/lib/commonjs/services/apiKeyService.js.map +1 -1
- package/lib/commonjs/services/platformAuthService.js +127 -290
- package/lib/commonjs/services/platformAuthService.js.map +1 -1
- package/lib/commonjs/utils/onairosApi.js +143 -71
- package/lib/commonjs/utils/onairosApi.js.map +1 -1
- package/lib/commonjs/utils/secureStorage.js +123 -1
- package/lib/commonjs/utils/secureStorage.js.map +1 -1
- package/lib/module/components/EmailVerificationModal.js +7 -5
- package/lib/module/components/EmailVerificationModal.js.map +1 -1
- package/lib/module/components/UniversalOnboarding.js +11 -2
- package/lib/module/components/UniversalOnboarding.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/apiKeyService.js +264 -22
- package/lib/module/services/apiKeyService.js.map +1 -1
- package/lib/module/services/platformAuthService.js +125 -287
- package/lib/module/services/platformAuthService.js.map +1 -1
- package/lib/module/utils/onairosApi.js +139 -70
- package/lib/module/utils/onairosApi.js.map +1 -1
- package/lib/module/utils/secureStorage.js +116 -0
- package/lib/module/utils/secureStorage.js.map +1 -1
- package/lib/typescript/components/EmailVerificationModal.d.ts.map +1 -1
- package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/services/apiKeyService.d.ts +50 -2
- package/lib/typescript/services/apiKeyService.d.ts.map +1 -1
- package/lib/typescript/services/platformAuthService.d.ts +29 -14
- package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
- package/lib/typescript/utils/onairosApi.d.ts +24 -10
- package/lib/typescript/utils/onairosApi.d.ts.map +1 -1
- package/lib/typescript/utils/secureStorage.d.ts +31 -0
- package/lib/typescript/utils/secureStorage.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/EmailVerificationModal.tsx +9 -5
- package/src/components/UniversalOnboarding.tsx +11 -1
- package/src/index.ts +1 -1
- package/src/services/apiKeyService.ts +282 -18
- package/src/services/platformAuthService.ts +216 -412
- package/src/types/index.d.ts +6 -5
- package/src/utils/onairosApi.ts +151 -74
- package/src/utils/secureStorage.ts +122 -0
|
@@ -3,59 +3,39 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.verifyEmailCode = exports.updateGoogleClientIds = exports.testApiConnectivity = exports.
|
|
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
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
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
|
|
16
|
-
* This
|
|
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
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Use production for email verification
|
|
36
|
-
enableLogging: true,
|
|
37
|
-
timeout: 30000
|
|
38
|
-
});
|
|
39
|
-
isApiKeyInitialized = true;
|
|
40
|
-
console.log('✅ Platform auth service initialized with admin key (production)');
|
|
20
|
+
// Check if app is already initialized with API key
|
|
21
|
+
const existingConfig = (0, _apiKeyService.getApiConfig)();
|
|
22
|
+
if (existingConfig && existingConfig.apiKey) {
|
|
23
|
+
console.log('🔑 Platform auth service using existing app configuration');
|
|
24
|
+
console.log(`✅ Environment: ${existingConfig.environment}`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
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.');
|
|
41
31
|
} catch (error) {
|
|
42
32
|
console.error('❌ Failed to initialize platform auth service:', error);
|
|
43
33
|
throw error;
|
|
44
34
|
}
|
|
45
35
|
};
|
|
46
36
|
|
|
47
|
-
/**
|
|
48
|
-
* Ensure API key is initialized before making authenticated requests
|
|
49
|
-
*/
|
|
50
|
-
exports.initializePlatformAuthService = initializePlatformAuthService;
|
|
51
|
-
const ensureApiKeyInitialized = async () => {
|
|
52
|
-
if (!isApiKeyInitialized) {
|
|
53
|
-
console.log('🔑 API key not initialized, initializing now...');
|
|
54
|
-
await initializePlatformAuthService();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
37
|
// Configuration for each platform's authentication
|
|
38
|
+
exports.initializePlatformAuthService = initializePlatformAuthService;
|
|
59
39
|
let PLATFORM_AUTH_CONFIG = {
|
|
60
40
|
instagram: {
|
|
61
41
|
hasNativeSDK: false,
|
|
@@ -165,7 +145,7 @@ const initiateOAuth = async (platform, username, appName) => {
|
|
|
165
145
|
}
|
|
166
146
|
};
|
|
167
147
|
console.log('📤 Sending Instagram OAuth request:', jsonData);
|
|
168
|
-
const response = await (0, _apiKeyService.
|
|
148
|
+
const response = await (0, _apiKeyService.makeDeveloperRequest)(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
169
149
|
method: 'POST',
|
|
170
150
|
body: JSON.stringify(jsonData)
|
|
171
151
|
});
|
|
@@ -203,7 +183,7 @@ const initiateOAuth = async (platform, username, appName) => {
|
|
|
203
183
|
console.log(`📤 Sending ${platform} OAuth request:`, jsonData);
|
|
204
184
|
|
|
205
185
|
// Make the authenticated request to get the OAuth URL
|
|
206
|
-
const response = await (0, _apiKeyService.
|
|
186
|
+
const response = await (0, _apiKeyService.makeDeveloperRequest)(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
207
187
|
method: 'POST',
|
|
208
188
|
body: JSON.stringify(jsonData)
|
|
209
189
|
});
|
|
@@ -812,360 +792,217 @@ const updateGoogleClientIds = config => {
|
|
|
812
792
|
};
|
|
813
793
|
|
|
814
794
|
/**
|
|
815
|
-
*
|
|
816
|
-
*
|
|
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
|
|
817
799
|
*/
|
|
818
800
|
exports.updateGoogleClientIds = updateGoogleClientIds;
|
|
819
801
|
const requestEmailVerification = async (email, testMode = false) => {
|
|
820
802
|
try {
|
|
821
803
|
console.log('📧 Requesting email verification for:', email);
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
if (
|
|
832
|
-
console.log('
|
|
833
|
-
const mockRequestId = 'test-request-' + Date.now();
|
|
834
|
-
|
|
835
|
-
// Store request info for tracking
|
|
836
|
-
await _asyncStorage.default.setItem('email_verification_request_id', mockRequestId);
|
|
837
|
-
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');
|
|
838
815
|
return {
|
|
839
816
|
success: true,
|
|
840
|
-
message: '
|
|
841
|
-
requestId: mockRequestId
|
|
817
|
+
message: data.message || 'Verification code sent to your email'
|
|
842
818
|
};
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
// Production mode: Make real API call with API key authentication
|
|
846
|
-
try {
|
|
847
|
-
// 🔑 Ensure API key is initialized before making authenticated requests
|
|
848
|
-
await ensureApiKeyInitialized();
|
|
849
|
-
const response = await (0, _apiKeyService.makeAuthenticatedRequest)('/email/verification', {
|
|
850
|
-
method: 'POST',
|
|
851
|
-
body: JSON.stringify({
|
|
852
|
-
email,
|
|
853
|
-
action: 'request'
|
|
854
|
-
})
|
|
855
|
-
});
|
|
856
|
-
const result = await response.json();
|
|
857
|
-
console.log('📡 Email verification API response:', result);
|
|
858
|
-
if (response.ok && result.success) {
|
|
859
|
-
console.log('✅ Email verification request sent');
|
|
860
|
-
|
|
861
|
-
// Store request info for tracking
|
|
862
|
-
const requestId = result.requestId || result.id || 'req-' + Date.now();
|
|
863
|
-
await _asyncStorage.default.setItem('email_verification_request_id', requestId);
|
|
864
|
-
await _asyncStorage.default.setItem('email_verification_request_email', email);
|
|
865
|
-
return {
|
|
866
|
-
success: true,
|
|
867
|
-
message: result.message || 'Email verification sent successfully',
|
|
868
|
-
requestId: requestId
|
|
869
|
-
};
|
|
870
|
-
} else {
|
|
871
|
-
console.error('❌ Email verification request failed:', result.error);
|
|
872
|
-
return {
|
|
873
|
-
success: false,
|
|
874
|
-
error: result.error || 'Failed to send verification email'
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
} catch (apiError) {
|
|
878
|
-
console.error('❌ Email verification API call failed:', apiError);
|
|
819
|
+
} else {
|
|
820
|
+
console.error('❌ Email verification request failed:', data.error);
|
|
879
821
|
return {
|
|
880
822
|
success: false,
|
|
881
|
-
error: '
|
|
823
|
+
error: data.error || 'Failed to send verification code'
|
|
882
824
|
};
|
|
883
825
|
}
|
|
884
826
|
} catch (error) {
|
|
885
|
-
console.error('❌
|
|
827
|
+
console.error('❌ Error requesting email verification:', error);
|
|
886
828
|
return {
|
|
887
829
|
success: false,
|
|
888
|
-
error: error instanceof Error ? error.message : '
|
|
830
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
889
831
|
};
|
|
890
832
|
}
|
|
891
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
|
+
*/
|
|
892
842
|
exports.requestEmailVerification = requestEmailVerification;
|
|
893
843
|
const verifyEmailCode = async (email, code, testMode = false) => {
|
|
894
844
|
try {
|
|
895
845
|
console.log('🔍 Verifying email code for:', email);
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
// Store mock token for API requests
|
|
917
|
-
await _asyncStorage.default.setItem('email_verification_token', mockToken);
|
|
918
|
-
await _asyncStorage.default.setItem('onairos_jwt_token', mockToken);
|
|
919
|
-
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
|
+
}
|
|
920
865
|
return {
|
|
921
866
|
success: true,
|
|
922
|
-
message: 'Email
|
|
923
|
-
existingUser: false,
|
|
924
|
-
|
|
867
|
+
message: data.message || 'Email verified successfully',
|
|
868
|
+
existingUser: data.existingUser || false,
|
|
869
|
+
token: data.token || data.jwtToken
|
|
925
870
|
};
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
// Production mode: Make real API call with API key authentication
|
|
929
|
-
try {
|
|
930
|
-
// 🔑 Ensure API key is initialized before making authenticated requests
|
|
931
|
-
await ensureApiKeyInitialized();
|
|
932
|
-
const response = await (0, _apiKeyService.makeAuthenticatedRequest)('/email/verification', {
|
|
933
|
-
method: 'POST',
|
|
934
|
-
body: JSON.stringify({
|
|
935
|
-
email,
|
|
936
|
-
code,
|
|
937
|
-
action: 'verify'
|
|
938
|
-
})
|
|
939
|
-
});
|
|
940
|
-
const result = await response.json();
|
|
941
|
-
console.log('📡 Email verification API response:', result);
|
|
942
|
-
if (response.ok && result.success) {
|
|
943
|
-
console.log('✅ Email verification successful');
|
|
944
|
-
|
|
945
|
-
// 🎫 CRITICAL: Store JWT token from email verification response
|
|
946
|
-
const jwtToken = result.token || result.jwtToken || result.jwt || result.authToken;
|
|
947
|
-
if (jwtToken) {
|
|
948
|
-
console.log('🎫 Storing JWT token from email verification response');
|
|
949
|
-
await _asyncStorage.default.setItem('email_verification_token', jwtToken);
|
|
950
|
-
await _asyncStorage.default.setItem('onairos_jwt_token', jwtToken);
|
|
951
|
-
await _asyncStorage.default.setItem('enoch_token', jwtToken);
|
|
952
|
-
await _asyncStorage.default.setItem('auth_token', jwtToken);
|
|
953
|
-
await _asyncStorage.default.setItem('email_verification_email', email);
|
|
954
|
-
await _asyncStorage.default.setItem('token_timestamp', Date.now().toString());
|
|
955
|
-
} else {
|
|
956
|
-
console.warn('⚠️ No JWT token received from email verification API');
|
|
957
|
-
}
|
|
958
|
-
return {
|
|
959
|
-
success: true,
|
|
960
|
-
message: result.message || 'Email verification successful',
|
|
961
|
-
existingUser: result.existingUser || false,
|
|
962
|
-
jwtToken: jwtToken
|
|
963
|
-
};
|
|
964
|
-
} else {
|
|
965
|
-
console.error('❌ Email verification failed:', result.error);
|
|
966
|
-
return {
|
|
967
|
-
success: false,
|
|
968
|
-
error: result.error || 'Email verification failed'
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
} catch (apiError) {
|
|
972
|
-
console.error('❌ Email verification API call failed:', apiError);
|
|
871
|
+
} else {
|
|
872
|
+
console.error('❌ Email verification failed:', data.error);
|
|
973
873
|
return {
|
|
974
874
|
success: false,
|
|
975
|
-
error:
|
|
875
|
+
error: data.error || 'Invalid verification code'
|
|
976
876
|
};
|
|
977
877
|
}
|
|
978
878
|
} catch (error) {
|
|
979
|
-
console.error('❌
|
|
879
|
+
console.error('❌ Error verifying email code:', error);
|
|
980
880
|
return {
|
|
981
881
|
success: false,
|
|
982
|
-
error: error instanceof Error ? error.message : '
|
|
882
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
983
883
|
};
|
|
984
884
|
}
|
|
985
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
|
+
*/
|
|
986
893
|
exports.verifyEmailCode = verifyEmailCode;
|
|
987
894
|
const checkEmailVerificationStatus = async (email, testMode = false) => {
|
|
988
895
|
try {
|
|
989
896
|
console.log('🔍 Checking email verification status for:', email);
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
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) {
|
|
995
906
|
return {
|
|
996
907
|
success: true,
|
|
997
|
-
isPending: false
|
|
998
|
-
message: 'Status retrieved successfully (test mode)'
|
|
908
|
+
isPending: data.isPending || false
|
|
999
909
|
};
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
// Production mode: Make real API call with API key authentication
|
|
1003
|
-
try {
|
|
1004
|
-
// 🔑 Ensure API key is initialized before making authenticated requests
|
|
1005
|
-
await ensureApiKeyInitialized();
|
|
1006
|
-
const response = await (0, _apiKeyService.makeAuthenticatedRequest)(`/email/verify/status/${encodeURIComponent(email)}`, {
|
|
1007
|
-
method: 'GET'
|
|
1008
|
-
});
|
|
1009
|
-
const result = await response.json();
|
|
1010
|
-
console.log('📡 Email verification status API response:', result);
|
|
1011
|
-
if (response.ok && result.success) {
|
|
1012
|
-
console.log('✅ Email verification status retrieved');
|
|
1013
|
-
return {
|
|
1014
|
-
success: true,
|
|
1015
|
-
isPending: result.isPending || false,
|
|
1016
|
-
message: result.message || 'Status retrieved successfully'
|
|
1017
|
-
};
|
|
1018
|
-
} else {
|
|
1019
|
-
console.error('❌ Email verification status failed:', result.error);
|
|
1020
|
-
return {
|
|
1021
|
-
success: false,
|
|
1022
|
-
error: result.error || 'Failed to check verification status'
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
} catch (apiError) {
|
|
1026
|
-
console.error('❌ Email verification status API call failed:', apiError);
|
|
910
|
+
} else {
|
|
1027
911
|
return {
|
|
1028
912
|
success: false,
|
|
1029
|
-
error: '
|
|
913
|
+
error: data.error || 'Failed to check verification status'
|
|
1030
914
|
};
|
|
1031
915
|
}
|
|
1032
916
|
} catch (error) {
|
|
1033
|
-
console.error('❌
|
|
917
|
+
console.error('❌ Error checking email verification status:', error);
|
|
1034
918
|
return {
|
|
1035
919
|
success: false,
|
|
1036
|
-
error: error instanceof Error ? error.message : '
|
|
920
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
1037
921
|
};
|
|
1038
922
|
}
|
|
1039
923
|
};
|
|
1040
924
|
|
|
1041
925
|
/**
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
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
|
|
1044
930
|
*/
|
|
1045
931
|
exports.checkEmailVerificationStatus = checkEmailVerificationStatus;
|
|
1046
932
|
const disconnectPlatform = async (platform, username) => {
|
|
1047
933
|
try {
|
|
1048
934
|
console.log('🔌 Disconnecting platform:', platform, 'for user:', username);
|
|
1049
|
-
if (!platform || !username) {
|
|
1050
|
-
return {
|
|
1051
|
-
success: false,
|
|
1052
|
-
error: 'Platform and username are required'
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
935
|
|
|
1056
936
|
// Make authenticated API call to disconnect platform
|
|
1057
|
-
const response = await (0, _apiKeyService.
|
|
937
|
+
const response = await (0, _apiKeyService.makeDeveloperRequest)('/revoke', {
|
|
1058
938
|
method: 'POST',
|
|
1059
939
|
body: JSON.stringify({
|
|
1060
940
|
platform,
|
|
1061
941
|
username
|
|
1062
942
|
})
|
|
1063
943
|
});
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
console.log('✅ Platform disconnected successfully');
|
|
944
|
+
const data = await response.json();
|
|
945
|
+
if (response.ok && data.success) {
|
|
946
|
+
console.log(`✅ ${platform} disconnected successfully`);
|
|
1068
947
|
return {
|
|
1069
|
-
success: true
|
|
1070
|
-
message: result.message || 'Platform disconnected successfully'
|
|
948
|
+
success: true
|
|
1071
949
|
};
|
|
1072
950
|
} else {
|
|
1073
|
-
console.error(
|
|
951
|
+
console.error(`❌ Failed to disconnect ${platform}:`, data.error);
|
|
1074
952
|
return {
|
|
1075
953
|
success: false,
|
|
1076
|
-
error:
|
|
954
|
+
error: data.error || 'Failed to disconnect platform'
|
|
1077
955
|
};
|
|
1078
956
|
}
|
|
1079
957
|
} catch (error) {
|
|
1080
|
-
console.error(
|
|
958
|
+
console.error(`❌ Error disconnecting ${platform}:`, error);
|
|
1081
959
|
return {
|
|
1082
960
|
success: false,
|
|
1083
|
-
error: error instanceof Error ? error.message : '
|
|
961
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
1084
962
|
};
|
|
1085
963
|
}
|
|
1086
964
|
};
|
|
1087
965
|
|
|
1088
966
|
/**
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
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
|
|
1091
971
|
*/
|
|
1092
972
|
exports.disconnectPlatform = disconnectPlatform;
|
|
1093
|
-
const
|
|
973
|
+
const storePIN = async (username, pin) => {
|
|
1094
974
|
try {
|
|
1095
|
-
console.log('🔐 Storing PIN
|
|
1096
|
-
console.log('🔑 PIN length:', pin.length);
|
|
1097
|
-
console.log('🎫 JWT token provided:', !!jwtToken);
|
|
1098
|
-
if (!username || !pin) {
|
|
1099
|
-
return {
|
|
1100
|
-
success: false,
|
|
1101
|
-
error: 'Username and PIN are required'
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
if (pin.length < 4) {
|
|
1105
|
-
return {
|
|
1106
|
-
success: false,
|
|
1107
|
-
error: 'PIN must be at least 4 digits'
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
// Get JWT token from storage if not provided
|
|
1112
|
-
let authToken = jwtToken;
|
|
1113
|
-
if (!authToken) {
|
|
1114
|
-
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'));
|
|
1115
|
-
}
|
|
1116
|
-
if (!authToken) {
|
|
1117
|
-
console.warn('⚠️ No JWT token available for PIN storage');
|
|
1118
|
-
return {
|
|
1119
|
-
success: false,
|
|
1120
|
-
error: 'No authentication token available'
|
|
1121
|
-
};
|
|
1122
|
-
}
|
|
1123
|
-
console.log('📤 Sending PIN to /store-pin/web endpoint');
|
|
975
|
+
console.log('🔐 Storing PIN for user:', username);
|
|
1124
976
|
|
|
1125
977
|
// Make authenticated request to store PIN
|
|
1126
|
-
const response = await (0, _apiKeyService.
|
|
978
|
+
const response = await (0, _apiKeyService.makeDeveloperRequest)('/store-pin/web', {
|
|
1127
979
|
method: 'POST',
|
|
1128
980
|
headers: {
|
|
1129
|
-
'
|
|
981
|
+
'Content-Type': 'application/json'
|
|
1130
982
|
},
|
|
1131
983
|
body: JSON.stringify({
|
|
1132
984
|
username,
|
|
1133
985
|
pin
|
|
1134
986
|
})
|
|
1135
987
|
});
|
|
1136
|
-
|
|
1137
|
-
if (
|
|
1138
|
-
|
|
1139
|
-
console.error('❌ PIN storage failed:', errorText);
|
|
1140
|
-
return {
|
|
1141
|
-
success: false,
|
|
1142
|
-
error: `PIN storage failed: ${response.status} - ${errorText}`
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
const result = await response.json();
|
|
1146
|
-
console.log('📥 PIN storage response:', result);
|
|
1147
|
-
if (result.success) {
|
|
1148
|
-
console.log('✅ PIN stored successfully after biometric authentication');
|
|
1149
|
-
|
|
1150
|
-
// Store PIN locally for future use
|
|
1151
|
-
await _asyncStorage.default.setItem('user_pin_stored', 'true');
|
|
1152
|
-
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');
|
|
1153
991
|
return {
|
|
1154
|
-
success: true
|
|
1155
|
-
message: result.message || 'PIN stored successfully'
|
|
992
|
+
success: true
|
|
1156
993
|
};
|
|
1157
994
|
} else {
|
|
1158
|
-
console.error('❌
|
|
995
|
+
console.error('❌ Failed to store PIN:', data.error);
|
|
1159
996
|
return {
|
|
1160
997
|
success: false,
|
|
1161
|
-
error:
|
|
998
|
+
error: data.error || 'Failed to store PIN'
|
|
1162
999
|
};
|
|
1163
1000
|
}
|
|
1164
1001
|
} catch (error) {
|
|
1165
|
-
console.error('❌ Error storing PIN
|
|
1002
|
+
console.error('❌ Error storing PIN:', error);
|
|
1166
1003
|
return {
|
|
1167
1004
|
success: false,
|
|
1168
|
-
error: error instanceof Error ? error.message : '
|
|
1005
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
1169
1006
|
};
|
|
1170
1007
|
}
|
|
1171
1008
|
};
|
|
@@ -1174,7 +1011,7 @@ const storePinAfterBiometric = async (username, pin, jwtToken) => {
|
|
|
1174
1011
|
* 🎫 GET STORED JWT TOKEN
|
|
1175
1012
|
* Helper function to retrieve stored JWT token from email verification or other sources
|
|
1176
1013
|
*/
|
|
1177
|
-
exports.
|
|
1014
|
+
exports.storePIN = storePIN;
|
|
1178
1015
|
const getStoredJwtToken = async () => {
|
|
1179
1016
|
try {
|
|
1180
1017
|
console.log('🎫 Retrieving stored JWT token...');
|