@onairos/react-native 3.0.49 → 3.0.51

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 (34) hide show
  1. package/lib/commonjs/components/EmailVerificationModal.js +317 -0
  2. package/lib/commonjs/components/EmailVerificationModal.js.map +1 -0
  3. package/lib/commonjs/components/TrainingModal.js +66 -75
  4. package/lib/commonjs/components/TrainingModal.js.map +1 -1
  5. package/lib/commonjs/components/UniversalOnboarding.js +30 -5
  6. package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
  7. package/lib/commonjs/index.js +60 -2
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/services/platformAuthService.js +505 -53
  10. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  11. package/lib/module/components/EmailVerificationModal.js +308 -0
  12. package/lib/module/components/EmailVerificationModal.js.map +1 -0
  13. package/lib/module/components/TrainingModal.js +66 -75
  14. package/lib/module/components/TrainingModal.js.map +1 -1
  15. package/lib/module/components/UniversalOnboarding.js +31 -6
  16. package/lib/module/components/UniversalOnboarding.js.map +1 -1
  17. package/lib/module/index.js +3 -1
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/services/platformAuthService.js +496 -52
  20. package/lib/module/services/platformAuthService.js.map +1 -1
  21. package/lib/typescript/components/EmailVerificationModal.d.ts +10 -0
  22. package/lib/typescript/components/EmailVerificationModal.d.ts.map +1 -0
  23. package/lib/typescript/components/TrainingModal.d.ts.map +1 -1
  24. package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
  25. package/lib/typescript/index.d.ts +4 -1
  26. package/lib/typescript/index.d.ts.map +1 -1
  27. package/lib/typescript/services/platformAuthService.d.ts +57 -1
  28. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  29. package/package.json +2 -1
  30. package/src/components/EmailVerificationModal.tsx +356 -0
  31. package/src/components/TrainingModal.tsx +69 -73
  32. package/src/components/UniversalOnboarding.tsx +31 -6
  33. package/src/index.ts +14 -1
  34. package/src/services/platformAuthService.ts +527 -55
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.testApiConnectivity = exports.isOAuthCallback = exports.initiateOAuth = exports.initiateNativeAuth = exports.hasNativeSDK = exports.handleOAuthCallback = exports.getPlatformColor = exports.getAuthEndpoint = void 0;
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;
7
+ var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
9
  // Define types for platform auth configuration
8
10
 
9
11
  // Configuration for each platform's authentication
10
- const PLATFORM_AUTH_CONFIG = {
12
+ let PLATFORM_AUTH_CONFIG = {
11
13
  instagram: {
12
14
  hasNativeSDK: false,
13
15
  // Instagram uses OAuth WebView flow
@@ -15,11 +17,15 @@ const PLATFORM_AUTH_CONFIG = {
15
17
  color: '#E1306C'
16
18
  },
17
19
  youtube: {
18
- hasNativeSDK: false,
20
+ hasNativeSDK: true,
19
21
  // Native Google Sign-In SDK enabled
20
22
  nativeSDKPackage: '@react-native-google-signin/google-signin',
21
23
  authEndpoint: 'https://api2.onairos.uk/youtube/authorize',
22
- color: '#FF0000'
24
+ color: '#FF0000',
25
+ clientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
26
+ redirectUri: 'onairosevents://auth/callback',
27
+ scope: 'https://www.googleapis.com/auth/youtube.readonly',
28
+ responseType: 'code'
23
29
  },
24
30
  reddit: {
25
31
  hasNativeSDK: false,
@@ -189,67 +195,192 @@ const initiateOAuth = async (platform, username, appName) => {
189
195
  * @returns A Promise that resolves to the authentication result
190
196
  */
191
197
  exports.initiateOAuth = initiateOAuth;
192
- const initiateNativeAuth = async platform => {
193
- try {
194
- // Currently only YouTube (Google Sign-In) is supported
195
- if (platform === 'youtube') {
196
- console.log('Initiating native Google Sign-In for YouTube');
198
+ const initiateNativeAuth = async (platform, username) => {
199
+ if (platform === 'youtube') {
200
+ console.log('🔗 Initiating native Google Sign-In for YouTube');
201
+ try {
202
+ var _userInfo$user, _currentUser$user, _userInfo$user4, _userInfo$user6, _userInfo$user7, _userInfo$user8;
203
+ // Import Google Sign-In dynamically to avoid errors if not installed
204
+ const {
205
+ GoogleSignin,
206
+ statusCodes
207
+ } = require('@react-native-google-signin/google-signin');
208
+
209
+ // Configure Google Sign-In
210
+ await GoogleSignin.configure({
211
+ webClientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
212
+ // Replace with your web client ID
213
+ iosClientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
214
+ // Replace with your iOS client ID
215
+ scopes: ['https://www.googleapis.com/auth/youtube.readonly'],
216
+ offlineAccess: true,
217
+ // CRITICAL: This ensures we get refresh tokens
218
+ hostedDomain: '',
219
+ forceCodeForRefreshToken: true,
220
+ // CRITICAL: Force refresh token on first sign-in
221
+ accountName: '' // Clear to avoid conflicts
222
+ });
223
+
224
+ // Check if Google Play Services are available
225
+ await GoogleSignin.hasPlayServices();
226
+
227
+ // Sign in with Google
228
+ const userInfo = await GoogleSignin.signIn();
229
+ console.log('✅ Google Sign-In successful:', (_userInfo$user = userInfo.user) === null || _userInfo$user === void 0 ? void 0 : _userInfo$user.email);
230
+
231
+ // Get access token for API calls
232
+ const tokens = await GoogleSignin.getTokens();
233
+ console.log('🔑 Got Google tokens');
234
+
235
+ // Get current user info with refresh token
236
+ const currentUser = await GoogleSignin.getCurrentUser();
237
+ console.log('👤 Current user info:', currentUser === null || currentUser === void 0 || (_currentUser$user = currentUser.user) === null || _currentUser$user === void 0 ? void 0 : _currentUser$user.email);
238
+
239
+ // Extract refresh token from server auth code
240
+ let refreshToken = null;
241
+ if (currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode) {
242
+ console.log('🔄 Server auth code available for refresh token');
243
+ refreshToken = currentUser.serverAuthCode;
244
+ }
245
+ if (!refreshToken) {
246
+ console.warn('⚠️ No refresh token available - token refresh may fail later');
247
+ } else {
248
+ console.log('✅ Refresh token available for YouTube connection');
249
+ }
250
+
251
+ // Fetch YouTube channel information
252
+ let channelName = 'Unknown Channel';
253
+ let channelId = null;
197
254
  try {
198
- // Import Google Sign-In dynamically to avoid errors if not installed
199
- const {
200
- GoogleSignin,
201
- statusCodes
202
- } = require('@react-native-google-signin/google-signin');
203
-
204
- // Configure Google Sign-In
205
- await GoogleSignin.configure({
206
- scopes: ['https://www.googleapis.com/auth/youtube.readonly', 'https://www.googleapis.com/auth/youtube.force-ssl'],
207
- webClientId: 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
208
- // Replace with your Web Client ID from Google Cloud Console
209
- iosClientId: 'YOUR_IOS_CLIENT_ID.apps.googleusercontent.com',
210
- // Replace with your iOS Client ID (iOS only)
211
- offlineAccess: true,
212
- hostedDomain: '',
213
- forceCodeForRefreshToken: true
255
+ console.log('📺 Fetching YouTube channel information...');
256
+ const channelResponse = await fetch('https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true', {
257
+ headers: {
258
+ 'Authorization': `Bearer ${tokens.accessToken}`,
259
+ 'Accept': 'application/json'
260
+ }
214
261
  });
262
+ if (channelResponse.ok) {
263
+ const channelData = await channelResponse.json();
264
+ if (channelData.items && channelData.items.length > 0) {
265
+ channelName = channelData.items[0].snippet.title;
266
+ channelId = channelData.items[0].id;
267
+ console.log('✅ YouTube channel found:', channelName);
268
+ }
269
+ }
270
+ } catch (channelError) {
271
+ var _userInfo$user2, _userInfo$user3;
272
+ console.log('⚠️ Error fetching YouTube channel info:', channelError);
273
+ channelName = ((_userInfo$user2 = userInfo.user) === null || _userInfo$user2 === void 0 ? void 0 : _userInfo$user2.name) || ((_userInfo$user3 = userInfo.user) === null || _userInfo$user3 === void 0 ? void 0 : _userInfo$user3.email) || 'Unknown Channel';
274
+ }
215
275
 
216
- // Check if device supports Google Play Services
217
- await GoogleSignin.hasPlayServices();
276
+ // Get authentication info
277
+ let authToken = (await _asyncStorage.default.getItem('onairos_jwt_token')) || (await _asyncStorage.default.getItem('enoch_token')) || (await _asyncStorage.default.getItem('auth_token'));
278
+ const storedUsername = await _asyncStorage.default.getItem('onairos_username');
279
+ const finalUsername = storedUsername || username || ((_userInfo$user4 = userInfo.user) === null || _userInfo$user4 === void 0 ? void 0 : _userInfo$user4.email) || 'youtube_user';
218
280
 
219
- // Sign in
220
- const userInfo = await GoogleSignin.signIn();
221
- console.log('Google Sign-In successful:', userInfo);
281
+ // Create auth token if needed
282
+ if (!authToken || authToken.trim().length < 20) {
283
+ console.log('🔐 Creating authentication token for YouTube...');
284
+ try {
285
+ var _userInfo$user5;
286
+ const fallbackEmail = ((_userInfo$user5 = userInfo.user) === null || _userInfo$user5 === void 0 ? void 0 : _userInfo$user5.email) || `${finalUsername}@youtube.temp`;
222
287
 
223
- // Get access token
224
- const tokens = await GoogleSignin.getTokens();
225
- console.log('Google tokens:', tokens);
288
+ // Create user accounts and get JWT token
289
+ const onairosSignupResponse = await fetch('https://api2.onairos.uk/register/enoch', {
290
+ method: 'POST',
291
+ headers: {
292
+ 'Content-Type': 'application/json'
293
+ },
294
+ body: JSON.stringify({
295
+ email: fallbackEmail,
296
+ username: finalUsername,
297
+ name: finalUsername
298
+ })
299
+ });
300
+ if (onairosSignupResponse.ok) {
301
+ var _onairosResponseData$;
302
+ const onairosResponseData = await onairosSignupResponse.json();
226
303
 
227
- // Here you would typically send the tokens to your backend
228
- // to associate the YouTube account with the user
304
+ // Extract token from response
305
+ authToken = onairosResponseData.token || ((_onairosResponseData$ = onairosResponseData.data) === null || _onairosResponseData$ === void 0 ? void 0 : _onairosResponseData$.token) || onairosResponseData.jwt;
306
+ if (authToken) {
307
+ // Store tokens
308
+ await _asyncStorage.default.setItem('onairos_jwt_token', authToken);
309
+ await _asyncStorage.default.setItem('enoch_token', authToken);
310
+ await _asyncStorage.default.setItem('auth_token', authToken);
311
+ await _asyncStorage.default.setItem('onairos_username', onairosResponseData.username || finalUsername);
312
+ console.log('✅ Successfully created and stored authentication token');
313
+ }
314
+ }
315
+ } catch (tokenError) {
316
+ console.warn('⚠️ Error creating auth token:', tokenError);
317
+ }
318
+ }
319
+ console.log('🔗 Linking YouTube data to user:', finalUsername);
320
+ console.log('📺 YouTube channel name:', channelName);
229
321
 
322
+ // Send tokens to backend for YouTube data processing
323
+ const backendResponse = await fetch('https://api2.onairos.uk/youtube/native-auth', {
324
+ method: 'POST',
325
+ headers: {
326
+ 'Content-Type': 'application/json',
327
+ ...(authToken && {
328
+ 'Authorization': `Bearer ${authToken}`
329
+ })
330
+ },
331
+ body: JSON.stringify({
332
+ session: {
333
+ username: finalUsername,
334
+ platform: 'youtube',
335
+ timestamp: new Date().toISOString(),
336
+ channelName: channelName,
337
+ channelId: channelId
338
+ },
339
+ googleUser: userInfo.user,
340
+ accessToken: tokens.accessToken,
341
+ idToken: tokens.idToken,
342
+ refreshToken: refreshToken,
343
+ // CRITICAL: Include refresh token
344
+ serverAuthCode: currentUser === null || currentUser === void 0 ? void 0 : currentUser.serverAuthCode,
345
+ userAccountInfo: {
346
+ username: finalUsername,
347
+ email: (_userInfo$user6 = userInfo.user) === null || _userInfo$user6 === void 0 ? void 0 : _userInfo$user6.email,
348
+ authToken: authToken,
349
+ channelName: channelName,
350
+ channelId: channelId,
351
+ userIdentifier: authToken ? `user-${authToken.substring(0, 10)}` : `youtube-${(_userInfo$user7 = userInfo.user) === null || _userInfo$user7 === void 0 ? void 0 : _userInfo$user7.email}`,
352
+ googleId: (_userInfo$user8 = userInfo.user) === null || _userInfo$user8 === void 0 ? void 0 : _userInfo$user8.id
353
+ },
354
+ tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
355
+ // 1 hour from now
356
+ requestRefreshToken: true
357
+ })
358
+ });
359
+ if (backendResponse.ok) {
360
+ const responseData = await backendResponse.json();
361
+ console.log('✅ YouTube connection processed by backend:', responseData);
230
362
  return true;
231
- } catch (error) {
232
- console.error('Google Sign-In error:', error);
233
- const {
234
- statusCodes: StatusCodes
235
- } = require('@react-native-google-signin/google-signin');
236
- if (error.code === StatusCodes.SIGN_IN_CANCELLED) {
237
- console.log('User cancelled the sign-in flow');
238
- } else if (error.code === StatusCodes.IN_PROGRESS) {
239
- console.log('Sign-in is in progress already');
240
- } else if (error.code === StatusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
241
- console.log('Play services not available or outdated');
242
- } else {
243
- console.log('Some other error happened');
244
- }
363
+ } else {
364
+ const errorData = await backendResponse.text();
365
+ console.error('❌ Backend processing failed:', backendResponse.status, errorData);
245
366
  return false;
246
367
  }
368
+ } catch (error) {
369
+ console.error('❌ Google Sign-In error:', error);
370
+ const {
371
+ statusCodes: StatusCodes
372
+ } = require('@react-native-google-signin/google-signin');
373
+ if (error.code === StatusCodes.SIGN_IN_CANCELLED) {
374
+ console.log('User cancelled Google Sign-In');
375
+ } else if (error.code === StatusCodes.IN_PROGRESS) {
376
+ console.log('Google Sign-In already in progress');
377
+ } else if (error.code === StatusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
378
+ console.log('Google Play Services not available');
379
+ }
380
+ return false;
247
381
  }
248
- throw new Error(`Native authentication not supported for ${platform}`);
249
- } catch (error) {
250
- console.error(`Error initiating native auth for ${platform}:`, error);
251
- throw error;
252
382
  }
383
+ return false;
253
384
  };
254
385
 
255
386
  /**
@@ -316,5 +447,326 @@ const testApiConnectivity = async () => {
316
447
  };
317
448
  }
318
449
  };
450
+
451
+ /**
452
+ * 🔄 REFRESH GOOGLE TOKENS
453
+ */
319
454
  exports.testApiConnectivity = testApiConnectivity;
455
+ const refreshGoogleTokens = async () => {
456
+ try {
457
+ console.log('🔄 Attempting to refresh Google tokens...');
458
+ const {
459
+ GoogleSignin
460
+ } = require('@react-native-google-signin/google-signin');
461
+ const currentUser = await GoogleSignin.getCurrentUser();
462
+ if (!currentUser) {
463
+ console.log('❌ User not signed in to Google, cannot refresh tokens');
464
+ return null;
465
+ }
466
+ const tokens = await GoogleSignin.getTokens();
467
+ console.log('✅ Successfully refreshed Google tokens');
468
+ return {
469
+ accessToken: tokens.accessToken,
470
+ idToken: tokens.idToken
471
+ };
472
+ } catch (error) {
473
+ console.error('❌ Failed to refresh Google tokens:', error);
474
+
475
+ // If refresh fails, try to sign in again
476
+ try {
477
+ console.log('🔄 Refresh failed, attempting re-authentication...');
478
+ const {
479
+ GoogleSignin
480
+ } = require('@react-native-google-signin/google-signin');
481
+ const userInfo = await GoogleSignin.signIn();
482
+ const tokens = await GoogleSignin.getTokens();
483
+ console.log('✅ Re-authentication successful');
484
+ return {
485
+ accessToken: tokens.accessToken,
486
+ idToken: tokens.idToken
487
+ };
488
+ } catch (signInError) {
489
+ console.error('❌ Re-authentication also failed:', signInError);
490
+ return null;
491
+ }
492
+ }
493
+ };
494
+
495
+ /**
496
+ * 🔄 REFRESH YOUTUBE TOKENS
497
+ */
498
+ exports.refreshGoogleTokens = refreshGoogleTokens;
499
+ const refreshYouTubeTokens = async () => {
500
+ try {
501
+ var _currentUser$user2;
502
+ console.log('🔄 Refreshing YouTube tokens...');
503
+
504
+ // Get fresh tokens from Google SDK
505
+ const freshTokens = await refreshGoogleTokens();
506
+ if (!freshTokens) {
507
+ console.error('❌ Failed to get fresh tokens from Google SDK');
508
+ return false;
509
+ }
510
+
511
+ // Get current user info
512
+ const {
513
+ GoogleSignin
514
+ } = require('@react-native-google-signin/google-signin');
515
+ const currentUser = await GoogleSignin.getCurrentUser();
516
+ if (!currentUser) {
517
+ console.error('❌ No current Google user found');
518
+ return false;
519
+ }
520
+
521
+ // Get stored auth token
522
+ const authToken = (await _asyncStorage.default.getItem('onairos_jwt_token')) || (await _asyncStorage.default.getItem('enoch_token')) || (await _asyncStorage.default.getItem('auth_token'));
523
+ if (!authToken) {
524
+ console.error('❌ No auth token found for YouTube refresh');
525
+ return false;
526
+ }
527
+
528
+ // Send refreshed tokens to backend
529
+ const refreshResponse = await fetch('https://api2.onairos.uk/youtube/refresh-token', {
530
+ method: 'POST',
531
+ headers: {
532
+ 'Content-Type': 'application/json',
533
+ 'Authorization': `Bearer ${authToken}`
534
+ },
535
+ body: JSON.stringify({
536
+ accessToken: freshTokens.accessToken,
537
+ idToken: freshTokens.idToken,
538
+ refreshToken: currentUser.serverAuthCode,
539
+ userEmail: (_currentUser$user2 = currentUser.user) === null || _currentUser$user2 === void 0 ? void 0 : _currentUser$user2.email,
540
+ tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
541
+ timestamp: new Date().toISOString()
542
+ })
543
+ });
544
+ if (refreshResponse.ok) {
545
+ const responseData = await refreshResponse.json();
546
+ console.log('✅ YouTube tokens refreshed successfully:', responseData);
547
+ return true;
548
+ } else {
549
+ const errorData = await refreshResponse.text();
550
+ console.error('❌ YouTube token refresh failed:', refreshResponse.status, errorData);
551
+ return false;
552
+ }
553
+ } catch (error) {
554
+ console.error('❌ Error refreshing YouTube tokens:', error);
555
+ return false;
556
+ }
557
+ };
558
+
559
+ /**
560
+ * 🎯 ENHANCED OAUTH CALLBACK HANDLER
561
+ */
562
+ exports.refreshYouTubeTokens = refreshYouTubeTokens;
563
+ const handleOAuthCallbackUrl = url => {
564
+ try {
565
+ console.log('🔍 Processing OAuth callback URL:', url);
566
+
567
+ // Parse the URL
568
+ const parsedUrl = new URL(url);
569
+
570
+ // Extract platform and code
571
+ const platform = parsedUrl.searchParams.get('platform') || parsedUrl.pathname.split('/').find(segment => ['instagram', 'youtube', 'reddit', 'pinterest', 'email'].includes(segment));
572
+ const code = parsedUrl.searchParams.get('code');
573
+ const error = parsedUrl.searchParams.get('error');
574
+ if (error) {
575
+ console.error('❌ OAuth error in callback:', error);
576
+ return {
577
+ success: false
578
+ };
579
+ }
580
+ if (code && platform) {
581
+ console.log(`✅ OAuth callback processed: ${platform} with code: ${code.substring(0, 10)}...`);
582
+ return {
583
+ platform,
584
+ code,
585
+ success: true
586
+ };
587
+ }
588
+ console.warn('⚠️ OAuth callback missing platform or code');
589
+ return {
590
+ success: false
591
+ };
592
+ } catch (error) {
593
+ console.error('❌ Error processing OAuth callback:', error);
594
+ return {
595
+ success: false
596
+ };
597
+ }
598
+ };
599
+
600
+ /**
601
+ * 🔧 UPDATE GOOGLE CLIENT IDS
602
+ * Allows apps to configure their own Google client IDs
603
+ */
604
+ exports.handleOAuthCallbackUrl = handleOAuthCallbackUrl;
605
+ const updateGoogleClientIds = config => {
606
+ console.log('🔧 Updating Google client IDs configuration');
607
+ if (config.webClientId || config.iosClientId) {
608
+ // Update the YouTube configuration
609
+ PLATFORM_AUTH_CONFIG.youtube = {
610
+ ...PLATFORM_AUTH_CONFIG.youtube,
611
+ clientId: config.webClientId || PLATFORM_AUTH_CONFIG.youtube.clientId
612
+ };
613
+ console.log('✅ Google client IDs updated successfully');
614
+ }
615
+ };
616
+
617
+ /**
618
+ * 📧 EMAIL VERIFICATION FUNCTIONS
619
+ * Using the correct Onairos email verification endpoints
620
+ */
621
+ exports.updateGoogleClientIds = updateGoogleClientIds;
622
+ const requestEmailVerification = async email => {
623
+ try {
624
+ console.log('📧 Requesting email verification for:', email);
625
+ const response = await fetch('https://api2.onairos.uk/email/verify', {
626
+ method: 'POST',
627
+ headers: {
628
+ 'Content-Type': 'application/json'
629
+ },
630
+ body: JSON.stringify({
631
+ email
632
+ })
633
+ });
634
+ const result = await response.json();
635
+ if (response.ok && result.success) {
636
+ console.log('✅ Email verification requested successfully');
637
+ console.log('🔍 Testing mode: Code logged to server console, but accepts any code');
638
+ return {
639
+ success: true,
640
+ message: result.message || 'Verification code sent to your email (testing mode: any code accepted)'
641
+ };
642
+ } else {
643
+ console.error('❌ Email verification request failed:', result.error);
644
+ return {
645
+ success: false,
646
+ error: result.error || 'Failed to send verification code'
647
+ };
648
+ }
649
+ } catch (error) {
650
+ console.error('❌ Email verification request error:', error);
651
+ return {
652
+ success: false,
653
+ error: error instanceof Error ? error.message : 'Network error'
654
+ };
655
+ }
656
+ };
657
+ exports.requestEmailVerification = requestEmailVerification;
658
+ const verifyEmailCode = async (email, code) => {
659
+ try {
660
+ console.log('🔍 Verifying email code for:', email);
661
+ const response = await fetch('https://api2.onairos.uk/email/verify/confirm', {
662
+ method: 'POST',
663
+ headers: {
664
+ 'Content-Type': 'application/json'
665
+ },
666
+ body: JSON.stringify({
667
+ email,
668
+ code
669
+ })
670
+ });
671
+ const result = await response.json();
672
+ if (response.ok && result.success) {
673
+ console.log('✅ Email verification successful');
674
+ console.log('🔍 Testing mode: Any code accepted for verification');
675
+ return {
676
+ success: true,
677
+ message: result.message || 'Email verified successfully'
678
+ };
679
+ } else {
680
+ console.error('❌ Email verification failed:', result.error);
681
+ return {
682
+ success: false,
683
+ error: result.error || 'Invalid verification code'
684
+ };
685
+ }
686
+ } catch (error) {
687
+ console.error('❌ Email verification error:', error);
688
+ return {
689
+ success: false,
690
+ error: error instanceof Error ? error.message : 'Network error'
691
+ };
692
+ }
693
+ };
694
+ exports.verifyEmailCode = verifyEmailCode;
695
+ const checkEmailVerificationStatus = async email => {
696
+ try {
697
+ console.log('🔍 Checking email verification status for:', email);
698
+ const response = await fetch(`https://api2.onairos.uk/email/verify/status/${encodeURIComponent(email)}`, {
699
+ method: 'GET',
700
+ headers: {
701
+ 'Content-Type': 'application/json'
702
+ }
703
+ });
704
+ const result = await response.json();
705
+ if (response.ok) {
706
+ console.log('✅ Email verification status retrieved');
707
+ return {
708
+ success: true,
709
+ isPending: result.isPending || false,
710
+ message: result.message || 'Status retrieved successfully'
711
+ };
712
+ } else {
713
+ console.error('❌ Email verification status check failed:', result.error);
714
+ return {
715
+ success: false,
716
+ error: result.error || 'Failed to check verification status'
717
+ };
718
+ }
719
+ } catch (error) {
720
+ console.error('❌ Email verification status error:', error);
721
+ return {
722
+ success: false,
723
+ error: error instanceof Error ? error.message : 'Network error'
724
+ };
725
+ }
726
+ };
727
+
728
+ /**
729
+ * 🔌 UNIVERSAL PLATFORM DISCONNECTION
730
+ * Backend confirmed this endpoint is fully implemented
731
+ */
732
+ exports.checkEmailVerificationStatus = checkEmailVerificationStatus;
733
+ const disconnectPlatform = async (platform, username) => {
734
+ try {
735
+ console.log(`🔌 Disconnecting ${platform} for user:`, username);
736
+ const response = await fetch('https://api2.onairos.uk/revoke', {
737
+ method: 'POST',
738
+ headers: {
739
+ 'Content-Type': 'application/json'
740
+ },
741
+ body: JSON.stringify({
742
+ Info: {
743
+ connection: platform.charAt(0).toUpperCase() + platform.slice(1),
744
+ // Capitalize platform name
745
+ username: username
746
+ }
747
+ })
748
+ });
749
+ const result = await response.json();
750
+ if (response.ok && result.success) {
751
+ console.log(`✅ ${platform} disconnected successfully`);
752
+ return {
753
+ success: true,
754
+ message: result.message || `${platform} disconnected successfully`
755
+ };
756
+ } else {
757
+ console.error(`❌ ${platform} disconnection failed:`, result.error);
758
+ return {
759
+ success: false,
760
+ error: result.error || `Failed to disconnect ${platform}`
761
+ };
762
+ }
763
+ } catch (error) {
764
+ console.error(`❌ ${platform} disconnection error:`, error);
765
+ return {
766
+ success: false,
767
+ error: error instanceof Error ? error.message : 'Network error'
768
+ };
769
+ }
770
+ };
771
+ exports.disconnectPlatform = disconnectPlatform;
320
772
  //# sourceMappingURL=platformAuthService.js.map