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