@onairos/react-native 3.0.75 → 3.1.1
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/index.js +18 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/apiKeyService.js +401 -27
- package/lib/commonjs/services/apiKeyService.js.map +1 -1
- package/lib/commonjs/services/platformAuthService.js +130 -299
- package/lib/commonjs/services/platformAuthService.js.map +1 -1
- package/lib/commonjs/utils/onairosApi.js +151 -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/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/apiKeyService.js +384 -22
- package/lib/module/services/apiKeyService.js.map +1 -1
- package/lib/module/services/platformAuthService.js +127 -295
- package/lib/module/services/platformAuthService.js.map +1 -1
- package/lib/module/utils/onairosApi.js +147 -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/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/services/apiKeyService.d.ts +68 -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 +25 -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/index.ts +4 -1
- package/src/services/apiKeyService.ts +412 -18
- package/src/services/platformAuthService.ts +219 -421
- package/src/types/index.d.ts +11 -5
- package/src/utils/onairosApi.ts +162 -74
- 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.
|
|
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
|
-
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('🔑
|
|
35
|
-
|
|
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
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
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.
|
|
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.
|
|
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,226 @@ const updateGoogleClientIds = config => {
|
|
|
827
792
|
};
|
|
828
793
|
|
|
829
794
|
/**
|
|
830
|
-
*
|
|
831
|
-
*
|
|
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
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
if (
|
|
847
|
-
console.log('
|
|
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: '
|
|
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: '
|
|
823
|
+
error: data.error || 'Failed to send verification code'
|
|
897
824
|
};
|
|
898
825
|
}
|
|
899
826
|
} catch (error) {
|
|
900
|
-
console.error('❌
|
|
827
|
+
console.error('❌ Error requesting email verification:', error);
|
|
901
828
|
return {
|
|
902
829
|
success: false,
|
|
903
|
-
error: error instanceof Error ? error.message : '
|
|
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
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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
|
|
938
|
-
existingUser: false,
|
|
939
|
-
|
|
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:
|
|
875
|
+
error: data.error || 'Invalid verification code'
|
|
991
876
|
};
|
|
992
877
|
}
|
|
993
878
|
} catch (error) {
|
|
994
|
-
console.error('❌
|
|
879
|
+
console.error('❌ Error verifying email code:', error);
|
|
995
880
|
return {
|
|
996
881
|
success: false,
|
|
997
|
-
error: error instanceof Error ? error.message : '
|
|
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
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
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: '
|
|
913
|
+
error: data.error || 'Failed to check verification status'
|
|
1045
914
|
};
|
|
1046
915
|
}
|
|
1047
916
|
} catch (error) {
|
|
1048
|
-
console.error('❌
|
|
917
|
+
console.error('❌ Error checking email verification status:', error);
|
|
1049
918
|
return {
|
|
1050
919
|
success: false,
|
|
1051
|
-
error: error instanceof Error ? error.message : '
|
|
920
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
1052
921
|
};
|
|
1053
922
|
}
|
|
1054
923
|
};
|
|
1055
924
|
|
|
1056
925
|
/**
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
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.
|
|
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
|
|
1080
|
-
|
|
1081
|
-
|
|
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(
|
|
951
|
+
console.error(`❌ Failed to disconnect ${platform}:`, data.error);
|
|
1089
952
|
return {
|
|
1090
953
|
success: false,
|
|
1091
|
-
error:
|
|
954
|
+
error: data.error || 'Failed to disconnect platform'
|
|
1092
955
|
};
|
|
1093
956
|
}
|
|
1094
957
|
} catch (error) {
|
|
1095
|
-
console.error(
|
|
958
|
+
console.error(`❌ Error disconnecting ${platform}:`, error);
|
|
1096
959
|
return {
|
|
1097
960
|
success: false,
|
|
1098
|
-
error: error instanceof Error ? error.message : '
|
|
961
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
1099
962
|
};
|
|
1100
963
|
}
|
|
1101
964
|
};
|
|
1102
965
|
|
|
1103
966
|
/**
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
967
|
+
* Store PIN for user (uses JWT authentication and extracts username from JWT)
|
|
968
|
+
* @param pin User PIN
|
|
969
|
+
* @param username Optional username (if not provided, extracts from JWT)
|
|
970
|
+
* @returns Promise with result
|
|
1106
971
|
*/
|
|
1107
972
|
exports.disconnectPlatform = disconnectPlatform;
|
|
1108
|
-
const
|
|
973
|
+
const storePIN = async (pin, username) => {
|
|
1109
974
|
try {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
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');
|
|
975
|
+
// Extract username from JWT if not provided
|
|
976
|
+
const userToStore = username || (0, _apiKeyService.extractUsernameFromJWT)();
|
|
977
|
+
if (!userToStore) {
|
|
978
|
+
console.error('❌ No username available - either provide username or ensure JWT token is valid');
|
|
1133
979
|
return {
|
|
1134
980
|
success: false,
|
|
1135
|
-
error: 'No
|
|
981
|
+
error: 'No username available for PIN storage'
|
|
1136
982
|
};
|
|
1137
983
|
}
|
|
1138
|
-
console.log('
|
|
984
|
+
console.log('🔐 Storing PIN for user:', userToStore);
|
|
1139
985
|
|
|
1140
|
-
// Make authenticated request to store PIN
|
|
1141
|
-
const response = await (0, _apiKeyService.
|
|
986
|
+
// Make authenticated request to store PIN (using developer API key for now)
|
|
987
|
+
const response = await (0, _apiKeyService.makeDeveloperRequest)('/store-pin/web', {
|
|
1142
988
|
method: 'POST',
|
|
1143
989
|
headers: {
|
|
1144
|
-
'
|
|
990
|
+
'Content-Type': 'application/json'
|
|
1145
991
|
},
|
|
1146
992
|
body: JSON.stringify({
|
|
1147
|
-
username,
|
|
993
|
+
username: userToStore,
|
|
1148
994
|
pin
|
|
1149
995
|
})
|
|
1150
996
|
});
|
|
1151
|
-
|
|
1152
|
-
if (
|
|
1153
|
-
|
|
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());
|
|
997
|
+
const data = await response.json();
|
|
998
|
+
if (response.ok && data.success) {
|
|
999
|
+
console.log('✅ PIN stored successfully for user:', userToStore);
|
|
1168
1000
|
return {
|
|
1169
|
-
success: true
|
|
1170
|
-
message: result.message || 'PIN stored successfully'
|
|
1001
|
+
success: true
|
|
1171
1002
|
};
|
|
1172
1003
|
} else {
|
|
1173
|
-
console.error('❌
|
|
1004
|
+
console.error('❌ Failed to store PIN:', data.error);
|
|
1174
1005
|
return {
|
|
1175
1006
|
success: false,
|
|
1176
|
-
error:
|
|
1007
|
+
error: data.error || 'Failed to store PIN'
|
|
1177
1008
|
};
|
|
1178
1009
|
}
|
|
1179
1010
|
} catch (error) {
|
|
1180
|
-
console.error('❌ Error storing PIN
|
|
1011
|
+
console.error('❌ Error storing PIN:', error);
|
|
1181
1012
|
return {
|
|
1182
1013
|
success: false,
|
|
1183
|
-
error: error instanceof Error ? error.message : '
|
|
1014
|
+
error: error instanceof Error ? error.message : 'Network error'
|
|
1184
1015
|
};
|
|
1185
1016
|
}
|
|
1186
1017
|
};
|
|
@@ -1189,7 +1020,7 @@ const storePinAfterBiometric = async (username, pin, jwtToken) => {
|
|
|
1189
1020
|
* 🎫 GET STORED JWT TOKEN
|
|
1190
1021
|
* Helper function to retrieve stored JWT token from email verification or other sources
|
|
1191
1022
|
*/
|
|
1192
|
-
exports.
|
|
1023
|
+
exports.storePIN = storePIN;
|
|
1193
1024
|
const getStoredJwtToken = async () => {
|
|
1194
1025
|
try {
|
|
1195
1026
|
console.log('🎫 Retrieving stored JWT token...');
|