@onairos/react-native 3.1.12 โ 3.1.14
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/README.md +403 -374
- package/lib/commonjs/api/index.js +75 -1
- package/lib/commonjs/api/index.js.map +1 -1
- package/lib/commonjs/assets/fonts/EBGaramond-VariableFont_wght.ttf +0 -0
- package/lib/commonjs/assets/fonts/IBMPlexSans-VariableFont_wdth,wght.ttf +0 -0
- package/lib/commonjs/assets/icons/Facebookicon.png +0 -0
- package/lib/commonjs/assets/icons/Gmail.png +0 -0
- package/lib/commonjs/assets/icons/Linkedinicon.png +0 -0
- package/lib/commonjs/assets/icons/Redditicon.png +0 -0
- package/lib/commonjs/assets/icons/YouTubeicon2.png +0 -0
- package/lib/commonjs/assets/icons/YouTubeicon3.png +0 -0
- package/lib/commonjs/assets/icons/farcaster.png +0 -0
- package/lib/commonjs/assets/icons/instagram.png +0 -0
- package/lib/commonjs/assets/icons/pinterest.png +0 -0
- package/lib/commonjs/assets/icons/swerv_logo.png +0 -0
- package/lib/commonjs/assets/icons/twitter.jpg +0 -0
- package/lib/commonjs/assets/images/Checkbox.svg +3 -0
- package/lib/commonjs/assets/images/EnochE.svg +19 -0
- package/lib/commonjs/assets/images/Enochicon1.png +0 -0
- package/lib/commonjs/assets/images/Face_ID_logo.png +0 -0
- package/lib/commonjs/assets/images/Facebookicon.png +0 -0
- package/lib/commonjs/assets/images/Gmail.png +0 -0
- package/lib/commonjs/assets/images/Googlelogo.png +0 -0
- package/lib/commonjs/assets/images/Linkedinicon.png +0 -0
- package/lib/commonjs/assets/images/Onairoslogo.png +0 -0
- package/lib/commonjs/assets/images/Personalityprofile.svg +3 -0
- package/lib/commonjs/assets/images/Personalitytraits.svg +3 -0
- package/lib/commonjs/assets/images/Redditicon.png +0 -0
- package/lib/commonjs/assets/images/Userpreferences.svg +3 -0
- package/lib/commonjs/assets/images/YouTubeicon3.png +0 -0
- package/lib/commonjs/assets/images/arrow.svg +20 -0
- package/lib/commonjs/assets/images/basicproficon.svg +43 -0
- package/lib/commonjs/assets/images/basicprofile.svg +3 -0
- package/lib/commonjs/assets/images/checkmark.svg +4 -0
- package/lib/commonjs/assets/images/contentanalysis.svg +3 -0
- package/lib/commonjs/assets/images/contenticon.svg +23 -0
- package/lib/commonjs/assets/images/persona1.png +0 -0
- package/lib/commonjs/assets/images/persona2.png +0 -0
- package/lib/commonjs/assets/images/persona3.png +0 -0
- package/lib/commonjs/assets/images/persona4.png +0 -0
- package/lib/commonjs/assets/images/persona5.png +0 -0
- package/lib/commonjs/assets/images/personalityicon.svg +18 -0
- package/lib/commonjs/assets/images/x-close.svg +3 -0
- package/lib/commonjs/components/BodyText.js +27 -0
- package/lib/commonjs/components/BodyText.js.map +1 -0
- package/lib/commonjs/components/BrandMark.js +44 -0
- package/lib/commonjs/components/BrandMark.js.map +1 -0
- package/lib/commonjs/components/CodeInput.js +30 -0
- package/lib/commonjs/components/CodeInput.js.map +1 -0
- package/lib/commonjs/components/EmailInput.js +30 -0
- package/lib/commonjs/components/EmailInput.js.map +1 -0
- package/lib/commonjs/components/ExistingUserDataConfirmation.js +474 -0
- package/lib/commonjs/components/ExistingUserDataConfirmation.js.map +1 -0
- package/lib/commonjs/components/GoogleButton.js +55 -0
- package/lib/commonjs/components/GoogleButton.js.map +1 -0
- package/lib/commonjs/components/HeadingGroup.js +43 -0
- package/lib/commonjs/components/HeadingGroup.js.map +1 -0
- package/lib/commonjs/components/ModalHeader.js +99 -0
- package/lib/commonjs/components/ModalHeader.js.map +1 -0
- package/lib/commonjs/components/ModalSheet.js +41 -0
- package/lib/commonjs/components/ModalSheet.js.map +1 -0
- package/lib/commonjs/components/Onairos.js +1 -3
- package/lib/commonjs/components/Onairos.js.map +1 -1
- package/lib/commonjs/components/OnairosButton.js +171 -190
- package/lib/commonjs/components/OnairosButton.js.map +1 -1
- package/lib/commonjs/components/OnairosSignInButton.js +169 -0
- package/lib/commonjs/components/OnairosSignInButton.js.map +1 -0
- package/lib/commonjs/components/Overlay.js +5 -5
- package/lib/commonjs/components/Overlay.js.map +1 -1
- package/lib/commonjs/components/PersonaImage.js +60 -0
- package/lib/commonjs/components/PersonaImage.js.map +1 -0
- package/lib/commonjs/components/PersonaLoadingScreen.js +156 -0
- package/lib/commonjs/components/PersonaLoadingScreen.js.map +1 -0
- package/lib/commonjs/components/PersonalizationConsentScreen.js +316 -0
- package/lib/commonjs/components/PersonalizationConsentScreen.js.map +1 -0
- package/lib/commonjs/components/PinCreationScreen.js +393 -0
- package/lib/commonjs/components/PinCreationScreen.js.map +1 -0
- package/lib/commonjs/components/PinInput.js +282 -120
- package/lib/commonjs/components/PinInput.js.map +1 -1
- package/lib/commonjs/components/PlatformConnectorsStep.js +828 -0
- package/lib/commonjs/components/PlatformConnectorsStep.js.map +1 -0
- package/lib/commonjs/components/PlatformToggle.js +180 -0
- package/lib/commonjs/components/PlatformToggle.js.map +1 -0
- package/lib/commonjs/components/PrimaryButton.js +180 -0
- package/lib/commonjs/components/PrimaryButton.js.map +1 -0
- package/lib/commonjs/components/SignInMatchAnimation.js +197 -0
- package/lib/commonjs/components/SignInMatchAnimation.js.map +1 -0
- package/lib/commonjs/components/SignInStep.js +179 -0
- package/lib/commonjs/components/SignInStep.js.map +1 -0
- package/lib/commonjs/components/TrainingModal.js +808 -563
- package/lib/commonjs/components/TrainingModal.js.map +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +2304 -1283
- package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
- package/lib/commonjs/components/VerificationStep.js +154 -0
- package/lib/commonjs/components/VerificationStep.js.map +1 -0
- package/lib/commonjs/components/WelcomeScreen.js +385 -0
- package/lib/commonjs/components/WelcomeScreen.js.map +1 -0
- package/lib/commonjs/components/icons/Basicproficon.js +37 -0
- package/lib/commonjs/components/icons/Basicproficon.js.map +1 -0
- package/lib/commonjs/components/icons/Basicprofile.js +21 -0
- package/lib/commonjs/components/icons/Basicprofile.js.map +1 -0
- package/lib/commonjs/components/icons/Checkbox.js +21 -0
- package/lib/commonjs/components/icons/Checkbox.js.map +1 -0
- package/lib/commonjs/components/icons/Checkmark.js +27 -0
- package/lib/commonjs/components/icons/Checkmark.js.map +1 -0
- package/lib/commonjs/components/icons/Contentanalysis.js +21 -0
- package/lib/commonjs/components/icons/Contentanalysis.js.map +1 -0
- package/lib/commonjs/components/icons/Contenticon.js +39 -0
- package/lib/commonjs/components/icons/Contenticon.js.map +1 -0
- package/lib/commonjs/components/icons/EnochE.js +41 -0
- package/lib/commonjs/components/icons/EnochE.js.map +1 -0
- package/lib/commonjs/components/icons/Personalityicon.js +30 -0
- package/lib/commonjs/components/icons/Personalityicon.js.map +1 -0
- package/lib/commonjs/components/icons/Personalityprofile.js +21 -0
- package/lib/commonjs/components/icons/Personalityprofile.js.map +1 -0
- package/lib/commonjs/components/icons/Personalitytraits.js +21 -0
- package/lib/commonjs/components/icons/Personalitytraits.js.map +1 -0
- package/lib/commonjs/components/icons/Userpreferences.js +21 -0
- package/lib/commonjs/components/icons/Userpreferences.js.map +1 -0
- package/lib/commonjs/components/icons/index.js +84 -0
- package/lib/commonjs/components/icons/index.js.map +1 -0
- package/lib/commonjs/components/onboarding/OAuthWebView.js +134 -743
- package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/commonjs/config/api.js +34 -0
- package/lib/commonjs/config/api.js.map +1 -0
- package/lib/commonjs/context/AuthContext.js +345 -0
- package/lib/commonjs/context/AuthContext.js.map +1 -0
- package/lib/commonjs/hooks/useConnectedAccounts.js +111 -0
- package/lib/commonjs/hooks/useConnectedAccounts.js.map +1 -0
- package/lib/commonjs/hooks/useConnections.js +120 -125
- package/lib/commonjs/hooks/useConnections.js.map +1 -1
- package/lib/commonjs/hooks/useUserConnections.js +148 -0
- package/lib/commonjs/hooks/useUserConnections.js.map +1 -0
- package/lib/commonjs/index.js +12 -100
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/apiClient.js +302 -0
- package/lib/commonjs/services/apiClient.js.map +1 -0
- package/lib/commonjs/services/apiKeyService.js +8 -9
- package/lib/commonjs/services/apiKeyService.js.map +1 -1
- package/lib/commonjs/services/authService.js +935 -0
- package/lib/commonjs/services/authService.js.map +1 -0
- package/lib/commonjs/services/biometricPinService.js +184 -0
- package/lib/commonjs/services/biometricPinService.js.map +1 -0
- package/lib/commonjs/services/connectedAccountsService.js +268 -0
- package/lib/commonjs/services/connectedAccountsService.js.map +1 -0
- package/lib/commonjs/services/googleAuthService.js +268 -0
- package/lib/commonjs/services/googleAuthService.js.map +1 -0
- package/lib/commonjs/services/imageCompressionService.js +260 -0
- package/lib/commonjs/services/imageCompressionService.js.map +1 -0
- package/lib/commonjs/services/jwtStorageService.js +256 -0
- package/lib/commonjs/services/jwtStorageService.js.map +1 -0
- package/lib/commonjs/services/mobileTrainingService.js +185 -0
- package/lib/commonjs/services/mobileTrainingService.js.map +1 -0
- package/lib/commonjs/services/pinEncryptionService.js +84 -0
- package/lib/commonjs/services/pinEncryptionService.js.map +1 -0
- package/lib/commonjs/services/pinStorageUtils.js +105 -0
- package/lib/commonjs/services/pinStorageUtils.js.map +1 -0
- package/lib/commonjs/services/platformAuthService.js +956 -722
- package/lib/commonjs/services/platformAuthService.js.map +1 -1
- package/lib/commonjs/services/storageService.js +404 -0
- package/lib/commonjs/services/storageService.js.map +1 -0
- package/lib/commonjs/services/trainingApiHelpers.js +73 -0
- package/lib/commonjs/services/trainingApiHelpers.js.map +1 -0
- package/lib/commonjs/services/userConnectionsService.js +486 -0
- package/lib/commonjs/services/userConnectionsService.js.map +1 -0
- package/lib/commonjs/services/youtubeMigrationService.js +415 -0
- package/lib/commonjs/services/youtubeMigrationService.js.map +1 -0
- package/lib/commonjs/theme/index.js +249 -0
- package/lib/commonjs/theme/index.js.map +1 -0
- package/lib/commonjs/utils/eventUtils.js +288 -0
- package/lib/commonjs/utils/eventUtils.js.map +1 -0
- package/lib/commonjs/utils/haptics.js +66 -0
- package/lib/commonjs/utils/haptics.js.map +1 -0
- package/lib/commonjs/utils/imagePreloader.js +6 -0
- package/lib/commonjs/utils/imagePreloader.js.map +1 -0
- package/lib/module/api/index.js +72 -0
- package/lib/module/api/index.js.map +1 -1
- package/lib/module/assets/fonts/EBGaramond-VariableFont_wght.ttf +0 -0
- package/lib/module/assets/fonts/IBMPlexSans-VariableFont_wdth,wght.ttf +0 -0
- package/lib/module/assets/icons/Facebookicon.png +0 -0
- package/lib/module/assets/icons/Gmail.png +0 -0
- package/lib/module/assets/icons/Linkedinicon.png +0 -0
- package/lib/module/assets/icons/Redditicon.png +0 -0
- package/lib/module/assets/icons/YouTubeicon2.png +0 -0
- package/lib/module/assets/icons/YouTubeicon3.png +0 -0
- package/lib/module/assets/icons/farcaster.png +0 -0
- package/lib/module/assets/icons/instagram.png +0 -0
- package/lib/module/assets/icons/pinterest.png +0 -0
- package/lib/module/assets/icons/swerv_logo.png +0 -0
- package/lib/module/assets/icons/twitter.jpg +0 -0
- package/lib/module/assets/images/Checkbox.svg +3 -0
- package/lib/module/assets/images/EnochE.svg +19 -0
- package/lib/module/assets/images/Enochicon1.png +0 -0
- package/lib/module/assets/images/Face_ID_logo.png +0 -0
- package/lib/module/assets/images/Facebookicon.png +0 -0
- package/lib/module/assets/images/Gmail.png +0 -0
- package/lib/module/assets/images/Googlelogo.png +0 -0
- package/lib/module/assets/images/Linkedinicon.png +0 -0
- package/lib/module/assets/images/Onairoslogo.png +0 -0
- package/lib/module/assets/images/Personalityprofile.svg +3 -0
- package/lib/module/assets/images/Personalitytraits.svg +3 -0
- package/lib/module/assets/images/Redditicon.png +0 -0
- package/lib/module/assets/images/Userpreferences.svg +3 -0
- package/lib/module/assets/images/YouTubeicon3.png +0 -0
- package/lib/module/assets/images/arrow.svg +20 -0
- package/lib/module/assets/images/basicproficon.svg +43 -0
- package/lib/module/assets/images/basicprofile.svg +3 -0
- package/lib/module/assets/images/checkmark.svg +4 -0
- package/lib/module/assets/images/contentanalysis.svg +3 -0
- package/lib/module/assets/images/contenticon.svg +23 -0
- package/lib/module/assets/images/persona1.png +0 -0
- package/lib/module/assets/images/persona2.png +0 -0
- package/lib/module/assets/images/persona3.png +0 -0
- package/lib/module/assets/images/persona4.png +0 -0
- package/lib/module/assets/images/persona5.png +0 -0
- package/lib/module/assets/images/personalityicon.svg +18 -0
- package/lib/module/assets/images/x-close.svg +3 -0
- package/lib/module/components/BodyText.js +20 -0
- package/lib/module/components/BodyText.js.map +1 -0
- package/lib/module/components/BrandMark.js +37 -0
- package/lib/module/components/BrandMark.js.map +1 -0
- package/lib/module/components/CodeInput.js +23 -0
- package/lib/module/components/CodeInput.js.map +1 -0
- package/lib/module/components/EmailInput.js +23 -0
- package/lib/module/components/EmailInput.js.map +1 -0
- package/lib/module/components/ExistingUserDataConfirmation.js +465 -0
- package/lib/module/components/ExistingUserDataConfirmation.js.map +1 -0
- package/lib/module/components/GoogleButton.js +48 -0
- package/lib/module/components/GoogleButton.js.map +1 -0
- package/lib/module/components/HeadingGroup.js +36 -0
- package/lib/module/components/HeadingGroup.js.map +1 -0
- package/lib/module/components/ModalHeader.js +92 -0
- package/lib/module/components/ModalHeader.js.map +1 -0
- package/lib/module/components/ModalSheet.js +34 -0
- package/lib/module/components/ModalSheet.js.map +1 -0
- package/lib/module/components/Onairos.js +1 -3
- package/lib/module/components/Onairos.js.map +1 -1
- package/lib/module/components/OnairosButton.js +172 -192
- package/lib/module/components/OnairosButton.js.map +1 -1
- package/lib/module/components/OnairosSignInButton.js +160 -0
- package/lib/module/components/OnairosSignInButton.js.map +1 -0
- package/lib/module/components/Overlay.js +5 -5
- package/lib/module/components/Overlay.js.map +1 -1
- package/lib/module/components/PersonaImage.js +53 -0
- package/lib/module/components/PersonaImage.js.map +1 -0
- package/lib/module/components/PersonaLoadingScreen.js +148 -0
- package/lib/module/components/PersonaLoadingScreen.js.map +1 -0
- package/lib/module/components/PersonalizationConsentScreen.js +309 -0
- package/lib/module/components/PersonalizationConsentScreen.js.map +1 -0
- package/lib/module/components/PinCreationScreen.js +386 -0
- package/lib/module/components/PinCreationScreen.js.map +1 -0
- package/lib/module/components/PinInput.js +283 -120
- package/lib/module/components/PinInput.js.map +1 -1
- package/lib/module/components/PlatformConnectorsStep.js +820 -0
- package/lib/module/components/PlatformConnectorsStep.js.map +1 -0
- package/lib/module/components/PlatformToggle.js +173 -0
- package/lib/module/components/PlatformToggle.js.map +1 -0
- package/lib/module/components/PrimaryButton.js +172 -0
- package/lib/module/components/PrimaryButton.js.map +1 -0
- package/lib/module/components/SignInMatchAnimation.js +189 -0
- package/lib/module/components/SignInMatchAnimation.js.map +1 -0
- package/lib/module/components/SignInStep.js +171 -0
- package/lib/module/components/SignInStep.js.map +1 -0
- package/lib/module/components/TrainingModal.js +809 -565
- package/lib/module/components/TrainingModal.js.map +1 -1
- package/lib/module/components/UniversalOnboarding.js +2307 -1284
- package/lib/module/components/UniversalOnboarding.js.map +1 -1
- package/lib/module/components/VerificationStep.js +146 -0
- package/lib/module/components/VerificationStep.js.map +1 -0
- package/lib/module/components/WelcomeScreen.js +378 -0
- package/lib/module/components/WelcomeScreen.js.map +1 -0
- package/lib/module/components/icons/Basicproficon.js +30 -0
- package/lib/module/components/icons/Basicproficon.js.map +1 -0
- package/lib/module/components/icons/Basicprofile.js +14 -0
- package/lib/module/components/icons/Basicprofile.js.map +1 -0
- package/lib/module/components/icons/Checkbox.js +14 -0
- package/lib/module/components/icons/Checkbox.js.map +1 -0
- package/lib/module/components/icons/Checkmark.js +20 -0
- package/lib/module/components/icons/Checkmark.js.map +1 -0
- package/lib/module/components/icons/Contentanalysis.js +14 -0
- package/lib/module/components/icons/Contentanalysis.js.map +1 -0
- package/lib/module/components/icons/Contenticon.js +32 -0
- package/lib/module/components/icons/Contenticon.js.map +1 -0
- package/lib/module/components/icons/EnochE.js +34 -0
- package/lib/module/components/icons/EnochE.js.map +1 -0
- package/lib/module/components/icons/Personalityicon.js +23 -0
- package/lib/module/components/icons/Personalityicon.js.map +1 -0
- package/lib/module/components/icons/Personalityprofile.js +14 -0
- package/lib/module/components/icons/Personalityprofile.js.map +1 -0
- package/lib/module/components/icons/Personalitytraits.js +14 -0
- package/lib/module/components/icons/Personalitytraits.js.map +1 -0
- package/lib/module/components/icons/Userpreferences.js +14 -0
- package/lib/module/components/icons/Userpreferences.js.map +1 -0
- package/lib/module/components/icons/index.js +13 -0
- package/lib/module/components/icons/index.js.map +1 -0
- package/lib/module/components/onboarding/OAuthWebView.js +136 -744
- package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/module/config/api.js +26 -0
- package/lib/module/config/api.js.map +1 -0
- package/lib/module/context/AuthContext.js +335 -0
- package/lib/module/context/AuthContext.js.map +1 -0
- package/lib/module/hooks/useConnectedAccounts.js +106 -0
- package/lib/module/hooks/useConnectedAccounts.js.map +1 -0
- package/lib/module/hooks/useConnections.js +119 -125
- package/lib/module/hooks/useConnections.js.map +1 -1
- package/lib/module/hooks/useUserConnections.js +140 -0
- package/lib/module/hooks/useUserConnections.js.map +1 -0
- package/lib/module/index.js +51 -15
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/apiClient.js +298 -0
- package/lib/module/services/apiClient.js.map +1 -0
- package/lib/module/services/apiKeyService.js +8 -9
- package/lib/module/services/apiKeyService.js.map +1 -1
- package/lib/module/services/authService.js +905 -0
- package/lib/module/services/authService.js.map +1 -0
- package/lib/module/services/biometricPinService.js +173 -0
- package/lib/module/services/biometricPinService.js.map +1 -0
- package/lib/module/services/connectedAccountsService.js +255 -0
- package/lib/module/services/connectedAccountsService.js.map +1 -0
- package/lib/module/services/googleAuthService.js +258 -0
- package/lib/module/services/googleAuthService.js.map +1 -0
- package/lib/module/services/imageCompressionService.js +250 -0
- package/lib/module/services/imageCompressionService.js.map +1 -0
- package/lib/module/services/jwtStorageService.js +239 -0
- package/lib/module/services/jwtStorageService.js.map +1 -0
- package/lib/module/services/mobileTrainingService.js +172 -0
- package/lib/module/services/mobileTrainingService.js.map +1 -0
- package/lib/module/services/pinEncryptionService.js +75 -0
- package/lib/module/services/pinEncryptionService.js.map +1 -0
- package/lib/module/services/pinStorageUtils.js +93 -0
- package/lib/module/services/pinStorageUtils.js.map +1 -0
- package/lib/module/services/platformAuthService.js +943 -704
- package/lib/module/services/platformAuthService.js.map +1 -1
- package/lib/module/services/storageService.js +383 -0
- package/lib/module/services/storageService.js.map +1 -0
- package/lib/module/services/trainingApiHelpers.js +67 -0
- package/lib/module/services/trainingApiHelpers.js.map +1 -0
- package/lib/module/services/userConnectionsService.js +476 -0
- package/lib/module/services/userConnectionsService.js.map +1 -0
- package/lib/module/services/youtubeMigrationService.js +404 -0
- package/lib/module/services/youtubeMigrationService.js.map +1 -0
- package/lib/module/theme/index.js +244 -0
- package/lib/module/theme/index.js.map +1 -0
- package/lib/module/utils/eventUtils.js +270 -0
- package/lib/module/utils/eventUtils.js.map +1 -0
- package/lib/module/utils/haptics.js +59 -0
- package/lib/module/utils/haptics.js.map +1 -0
- package/lib/module/utils/imagePreloader.js +3 -0
- package/lib/module/utils/imagePreloader.js.map +1 -0
- package/lib/typescript/api/index.d.ts +8 -0
- package/lib/typescript/api/index.d.ts.map +1 -1
- package/lib/typescript/components/BodyText.d.ts +10 -0
- package/lib/typescript/components/BodyText.d.ts.map +1 -0
- package/lib/typescript/components/BrandMark.d.ts +11 -0
- package/lib/typescript/components/BrandMark.d.ts.map +1 -0
- package/lib/typescript/components/CodeInput.d.ts +10 -0
- package/lib/typescript/components/CodeInput.d.ts.map +1 -0
- package/lib/typescript/components/EmailInput.d.ts +8 -0
- package/lib/typescript/components/EmailInput.d.ts.map +1 -0
- package/lib/typescript/components/ExistingUserDataConfirmation.d.ts +12 -0
- package/lib/typescript/components/ExistingUserDataConfirmation.d.ts.map +1 -0
- package/lib/typescript/components/GoogleButton.d.ts +11 -0
- package/lib/typescript/components/GoogleButton.d.ts.map +1 -0
- package/lib/typescript/components/HeadingGroup.d.ts +11 -0
- package/lib/typescript/components/HeadingGroup.d.ts.map +1 -0
- package/lib/typescript/components/ModalHeader.d.ts +11 -0
- package/lib/typescript/components/ModalHeader.d.ts.map +1 -0
- package/lib/typescript/components/ModalSheet.d.ts +13 -0
- package/lib/typescript/components/ModalSheet.d.ts.map +1 -0
- package/lib/typescript/components/Onairos.d.ts.map +1 -1
- package/lib/typescript/components/OnairosButton.d.ts +29 -4
- package/lib/typescript/components/OnairosButton.d.ts.map +1 -1
- package/lib/typescript/components/OnairosSignInButton.d.ts +14 -0
- package/lib/typescript/components/OnairosSignInButton.d.ts.map +1 -0
- package/lib/typescript/components/PersonaImage.d.ts +8 -0
- package/lib/typescript/components/PersonaImage.d.ts.map +1 -0
- package/lib/typescript/components/PersonaLoadingScreen.d.ts +10 -0
- package/lib/typescript/components/PersonaLoadingScreen.d.ts.map +1 -0
- package/lib/typescript/components/PersonalizationConsentScreen.d.ts +10 -0
- package/lib/typescript/components/PersonalizationConsentScreen.d.ts.map +1 -0
- package/lib/typescript/components/PinCreationScreen.d.ts +10 -0
- package/lib/typescript/components/PinCreationScreen.d.ts.map +1 -0
- package/lib/typescript/components/PinInput.d.ts +11 -1
- package/lib/typescript/components/PinInput.d.ts.map +1 -1
- package/lib/typescript/components/PlatformConnectorsStep.d.ts +11 -0
- package/lib/typescript/components/PlatformConnectorsStep.d.ts.map +1 -0
- package/lib/typescript/components/PlatformToggle.d.ts +20 -0
- package/lib/typescript/components/PlatformToggle.d.ts.map +1 -0
- package/lib/typescript/components/PrimaryButton.d.ts +22 -0
- package/lib/typescript/components/PrimaryButton.d.ts.map +1 -0
- package/lib/typescript/components/SignInMatchAnimation.d.ts +9 -0
- package/lib/typescript/components/SignInMatchAnimation.d.ts.map +1 -0
- package/lib/typescript/components/SignInStep.d.ts +12 -0
- package/lib/typescript/components/SignInStep.d.ts.map +1 -0
- package/lib/typescript/components/TrainingModal.d.ts +12 -1
- package/lib/typescript/components/TrainingModal.d.ts.map +1 -1
- package/lib/typescript/components/UniversalOnboarding.d.ts +14 -1
- package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
- package/lib/typescript/components/VerificationStep.d.ts +13 -0
- package/lib/typescript/components/VerificationStep.d.ts.map +1 -0
- package/lib/typescript/components/WelcomeScreen.d.ts +9 -0
- package/lib/typescript/components/WelcomeScreen.d.ts.map +1 -0
- package/lib/typescript/components/icons/Basicproficon.d.ts +5 -0
- package/lib/typescript/components/icons/Basicproficon.d.ts.map +1 -0
- package/lib/typescript/components/icons/Basicprofile.d.ts +5 -0
- package/lib/typescript/components/icons/Basicprofile.d.ts.map +1 -0
- package/lib/typescript/components/icons/Checkbox.d.ts +5 -0
- package/lib/typescript/components/icons/Checkbox.d.ts.map +1 -0
- package/lib/typescript/components/icons/Checkmark.d.ts +5 -0
- package/lib/typescript/components/icons/Checkmark.d.ts.map +1 -0
- package/lib/typescript/components/icons/Contentanalysis.d.ts +5 -0
- package/lib/typescript/components/icons/Contentanalysis.d.ts.map +1 -0
- package/lib/typescript/components/icons/Contenticon.d.ts +5 -0
- package/lib/typescript/components/icons/Contenticon.d.ts.map +1 -0
- package/lib/typescript/components/icons/EnochE.d.ts +5 -0
- package/lib/typescript/components/icons/EnochE.d.ts.map +1 -0
- package/lib/typescript/components/icons/Personalityicon.d.ts +5 -0
- package/lib/typescript/components/icons/Personalityicon.d.ts.map +1 -0
- package/lib/typescript/components/icons/Personalityprofile.d.ts +5 -0
- package/lib/typescript/components/icons/Personalityprofile.d.ts.map +1 -0
- package/lib/typescript/components/icons/Personalitytraits.d.ts +5 -0
- package/lib/typescript/components/icons/Personalitytraits.d.ts.map +1 -0
- package/lib/typescript/components/icons/Userpreferences.d.ts +5 -0
- package/lib/typescript/components/icons/Userpreferences.d.ts.map +1 -0
- package/lib/typescript/components/icons/index.d.ts +12 -0
- package/lib/typescript/components/icons/index.d.ts.map +1 -0
- package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
- package/lib/typescript/config/api.d.ts +24 -0
- package/lib/typescript/config/api.d.ts.map +1 -0
- package/lib/typescript/context/AuthContext.d.ts +34 -0
- package/lib/typescript/context/AuthContext.d.ts.map +1 -0
- package/lib/typescript/hooks/useConnectedAccounts.d.ts +11 -0
- package/lib/typescript/hooks/useConnectedAccounts.d.ts.map +1 -0
- package/lib/typescript/hooks/useConnections.d.ts +10 -5
- package/lib/typescript/hooks/useConnections.d.ts.map +1 -1
- package/lib/typescript/hooks/useUserConnections.d.ts +12 -0
- package/lib/typescript/hooks/useUserConnections.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +24 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/services/apiClient.d.ts +91 -0
- package/lib/typescript/services/apiClient.d.ts.map +1 -0
- package/lib/typescript/services/apiKeyService.d.ts.map +1 -1
- package/lib/typescript/services/authService.d.ts +216 -0
- package/lib/typescript/services/authService.d.ts.map +1 -0
- package/lib/typescript/services/biometricPinService.d.ts +29 -0
- package/lib/typescript/services/biometricPinService.d.ts.map +1 -0
- package/lib/typescript/services/connectedAccountsService.d.ts +56 -0
- package/lib/typescript/services/connectedAccountsService.d.ts.map +1 -0
- package/lib/typescript/services/googleAuthService.d.ts +63 -0
- package/lib/typescript/services/googleAuthService.d.ts.map +1 -0
- package/lib/typescript/services/imageCompressionService.d.ts +37 -0
- package/lib/typescript/services/imageCompressionService.d.ts.map +1 -0
- package/lib/typescript/services/jwtStorageService.d.ts +86 -0
- package/lib/typescript/services/jwtStorageService.d.ts.map +1 -0
- package/lib/typescript/services/mobileTrainingService.d.ts +45 -0
- package/lib/typescript/services/mobileTrainingService.d.ts.map +1 -0
- package/lib/typescript/services/pinEncryptionService.d.ts +17 -0
- package/lib/typescript/services/pinEncryptionService.d.ts.map +1 -0
- package/lib/typescript/services/pinStorageUtils.d.ts +25 -0
- package/lib/typescript/services/pinStorageUtils.d.ts.map +1 -0
- package/lib/typescript/services/platformAuthService.d.ts +34 -109
- package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
- package/lib/typescript/services/storageService.d.ts +128 -0
- package/lib/typescript/services/storageService.d.ts.map +1 -0
- package/lib/typescript/services/trainingApiHelpers.d.ts +38 -0
- package/lib/typescript/services/trainingApiHelpers.d.ts.map +1 -0
- package/lib/typescript/services/userConnectionsService.d.ts +90 -0
- package/lib/typescript/services/userConnectionsService.d.ts.map +1 -0
- package/lib/typescript/services/youtubeMigrationService.d.ts +12 -0
- package/lib/typescript/services/youtubeMigrationService.d.ts.map +1 -0
- package/lib/typescript/theme/index.d.ts +416 -0
- package/lib/typescript/theme/index.d.ts.map +1 -0
- package/lib/typescript/types/index.d.ts +39 -0
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/utils/eventUtils.d.ts +108 -0
- package/lib/typescript/utils/eventUtils.d.ts.map +1 -0
- package/lib/typescript/utils/haptics.d.ts +11 -0
- package/lib/typescript/utils/haptics.d.ts.map +1 -0
- package/lib/typescript/utils/imagePreloader.d.ts +2 -0
- package/lib/typescript/utils/imagePreloader.d.ts.map +1 -0
- package/package.json +163 -145
- package/src/api/index.ts +41 -0
- package/src/assets/fonts/EBGaramond-VariableFont_wght.ttf +0 -0
- package/src/assets/fonts/IBMPlexSans-VariableFont_wdth,wght.ttf +0 -0
- package/src/assets/icons/Facebookicon.png +0 -0
- package/src/assets/icons/Gmail.png +0 -0
- package/src/assets/icons/Linkedinicon.png +0 -0
- package/src/assets/icons/Redditicon.png +0 -0
- package/src/assets/icons/YouTubeicon2.png +0 -0
- package/src/assets/icons/YouTubeicon3.png +0 -0
- package/src/assets/icons/farcaster.png +0 -0
- package/src/assets/icons/instagram.png +0 -0
- package/src/assets/icons/pinterest.png +0 -0
- package/src/assets/icons/swerv_logo.png +0 -0
- package/src/assets/icons/twitter.jpg +0 -0
- package/src/assets/images/Checkbox.svg +3 -0
- package/src/assets/images/EnochE.svg +19 -0
- package/src/assets/images/Enochicon1.png +0 -0
- package/src/assets/images/Face_ID_logo.png +0 -0
- package/src/assets/images/Facebookicon.png +0 -0
- package/src/assets/images/Gmail.png +0 -0
- package/src/assets/images/Googlelogo.png +0 -0
- package/src/assets/images/Linkedinicon.png +0 -0
- package/src/assets/images/Onairoslogo.png +0 -0
- package/src/assets/images/Personalityprofile.svg +3 -0
- package/src/assets/images/Personalitytraits.svg +3 -0
- package/src/assets/images/Redditicon.png +0 -0
- package/src/assets/images/Userpreferences.svg +3 -0
- package/src/assets/images/YouTubeicon3.png +0 -0
- package/src/assets/images/arrow.svg +20 -0
- package/src/assets/images/basicproficon.svg +43 -0
- package/src/assets/images/basicprofile.svg +3 -0
- package/src/assets/images/checkmark.svg +4 -0
- package/src/assets/images/contentanalysis.svg +3 -0
- package/src/assets/images/contenticon.svg +23 -0
- package/src/assets/images/persona1.png +0 -0
- package/src/assets/images/persona2.png +0 -0
- package/src/assets/images/persona3.png +0 -0
- package/src/assets/images/persona4.png +0 -0
- package/src/assets/images/persona5.png +0 -0
- package/src/assets/images/personalityicon.svg +18 -0
- package/src/assets/images/x-close.svg +3 -0
- package/src/components/BodyText.tsx +33 -0
- package/src/components/BrandMark.tsx +62 -0
- package/src/components/CodeInput.tsx +32 -0
- package/src/components/EmailInput.tsx +31 -0
- package/src/components/ExistingUserDataConfirmation.tsx +507 -0
- package/src/components/GoogleButton.tsx +55 -0
- package/src/components/HeadingGroup.tsx +49 -0
- package/src/components/ModalHeader.tsx +125 -0
- package/src/components/ModalSheet.tsx +57 -0
- package/src/components/Onairos.tsx +422 -424
- package/src/components/OnairosButton.tsx +339 -359
- package/src/components/OnairosSignInButton.tsx +166 -0
- package/src/components/Overlay.tsx +506 -506
- package/src/components/PersonaImage.tsx +79 -0
- package/src/components/PersonaLoadingScreen.tsx +201 -0
- package/src/components/PersonalizationConsentScreen.tsx +410 -0
- package/src/components/PinCreationScreen.tsx +492 -0
- package/src/components/PinInput.tsx +555 -343
- package/src/components/PlatformConnectorsStep.tsx +892 -0
- package/src/components/PlatformToggle.tsx +226 -0
- package/src/components/PrimaryButton.tsx +214 -0
- package/src/components/SignInMatchAnimation.tsx +225 -0
- package/src/components/SignInStep.tsx +217 -0
- package/src/components/TrainingModal.tsx +1047 -737
- package/src/components/UniversalOnboarding.tsx +2888 -1820
- package/src/components/VerificationStep.tsx +198 -0
- package/src/components/WelcomeScreen.tsx +473 -0
- package/src/components/icons/Basicproficon.tsx +30 -0
- package/src/components/icons/Basicprofile.tsx +17 -0
- package/src/components/icons/Checkbox.tsx +17 -0
- package/src/components/icons/Checkmark.tsx +24 -0
- package/src/components/icons/Contentanalysis.tsx +17 -0
- package/src/components/icons/Contenticon.tsx +30 -0
- package/src/components/icons/EnochE.tsx +39 -0
- package/src/components/icons/Personalityicon.tsx +22 -0
- package/src/components/icons/Personalityprofile.tsx +17 -0
- package/src/components/icons/Personalitytraits.tsx +17 -0
- package/src/components/icons/Userpreferences.tsx +17 -0
- package/src/components/icons/index.ts +12 -0
- package/src/components/onboarding/OAuthWebView.tsx +232 -838
- package/src/config/api.ts +25 -0
- package/src/context/AuthContext.tsx +393 -0
- package/src/hooks/useConnectedAccounts.ts +139 -0
- package/src/hooks/useConnections.ts +129 -131
- package/src/hooks/useUserConnections.ts +166 -0
- package/src/index.ts +94 -49
- package/src/services/apiClient.ts +337 -0
- package/src/services/apiKeyService.ts +9 -11
- package/src/services/authService.ts +1008 -0
- package/src/services/biometricPinService.ts +193 -0
- package/src/services/connectedAccountsService.ts +290 -0
- package/src/services/googleAuthService.ts +279 -0
- package/src/services/imageCompressionService.ts +303 -0
- package/src/services/jwtStorageService.ts +257 -0
- package/src/services/mobileTrainingService.ts +204 -0
- package/src/services/pinEncryptionService.ts +76 -0
- package/src/services/pinStorageUtils.ts +97 -0
- package/src/services/platformAuthService.ts +1346 -1113
- package/src/services/storageService.ts +452 -0
- package/src/services/trainingApiHelpers.ts +67 -0
- package/src/services/userConnectionsService.ts +557 -0
- package/src/services/youtubeMigrationService.ts +454 -0
- package/src/theme/index.ts +239 -0
- package/src/types/index.ts +265 -238
- package/src/utils/eventUtils.ts +303 -0
- package/src/utils/haptics.ts +59 -0
- package/src/utils/imagePreloader.ts +2 -0
- package/lib/commonjs/assets/images/email.png +0 -0
- package/lib/commonjs/assets/images/linkedin.png +0 -0
- package/lib/commonjs/assets/images/reddit.png +0 -0
- package/lib/commonjs/assets/images/youtube.png +0 -0
- package/lib/commonjs/components/UniversalOnboarding.tsx.new +0 -455
- package/lib/module/assets/images/email.png +0 -0
- package/lib/module/assets/images/linkedin.png +0 -0
- package/lib/module/assets/images/reddit.png +0 -0
- package/lib/module/assets/images/youtube.png +0 -0
- package/lib/module/components/UniversalOnboarding.tsx.new +0 -455
- package/src/assets/images/email.png +0 -0
- package/src/assets/images/linkedin.png +0 -0
- package/src/assets/images/reddit.png +0 -0
- package/src/assets/images/youtube.png +0 -0
- package/src/components/UniversalOnboarding.tsx.new +0 -455
|
@@ -3,399 +3,753 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.verifyEmailCode = exports.
|
|
6
|
+
exports.verifyEmailCode = exports.testYouTubeRefreshToken = exports.requestEmailVerification = exports.refreshYouTubeTokens = exports.reconnectYouTube = exports.isOAuthCallback = exports.initiateOAuth = exports.initiateNativeAuth = exports.initializePlatformAuthService = exports.hasNativeSDK = exports.forceYouTubeReconnectionWithRevoke = exports.forceYouTubeReconnectionWithConsent = exports.fixUserYouTubeConnection = exports.exchangeCodeForToken = exports.checkEmailVerificationStatus = void 0;
|
|
7
|
+
var _googleSignin = require("@react-native-google-signin/google-signin");
|
|
7
8
|
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
8
|
-
var
|
|
9
|
+
var _api = require("../config/api");
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Initialize the platform auth service
|
|
16
|
-
* This service now uses the two-tier authentication system
|
|
11
|
+
/**
|
|
12
|
+
* Platform Authentication Service
|
|
13
|
+
* Handles OAuth flows for different platforms
|
|
17
14
|
*/
|
|
18
|
-
const initializePlatformAuthService = async () => {
|
|
19
|
-
try {
|
|
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
15
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Configuration for each platform's authentication
|
|
38
|
-
exports.initializePlatformAuthService = initializePlatformAuthService;
|
|
39
|
-
let PLATFORM_AUTH_CONFIG = {
|
|
16
|
+
// ๐ CRITICAL: Using the same client ID for both web and iOS to avoid audience errors
|
|
17
|
+
const WEB_CLIENT_ID = '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com';
|
|
18
|
+
const IOS_CLIENT_ID = '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com';
|
|
19
|
+
// OAuth configuration for different platforms
|
|
20
|
+
const OAUTH_CONFIG = {
|
|
40
21
|
instagram: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
22
|
+
authUrl: 'https://api.instagram.com/oauth/authorize',
|
|
23
|
+
clientId: 'demo_instagram_client_id',
|
|
24
|
+
redirectUri: 'onairosevents://auth/callback',
|
|
25
|
+
scope: 'user_profile,user_media',
|
|
26
|
+
responseType: 'code',
|
|
27
|
+
hasNativeSDK: false
|
|
45
28
|
},
|
|
46
29
|
youtube: {
|
|
47
|
-
|
|
48
|
-
// Native Google Sign-In SDK enabled
|
|
49
|
-
nativeSDKPackage: '@react-native-google-signin/google-signin',
|
|
50
|
-
authEndpoint: '/youtube/authorize',
|
|
51
|
-
color: '#FF0000',
|
|
30
|
+
authUrl: 'https://api2.onairos.uk/youtube/authorize',
|
|
52
31
|
clientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
|
|
53
32
|
redirectUri: 'onairosevents://auth/callback',
|
|
54
33
|
scope: 'https://www.googleapis.com/auth/youtube.readonly',
|
|
55
|
-
responseType: 'code'
|
|
34
|
+
responseType: 'code',
|
|
35
|
+
hasNativeSDK: true // Changed to true for native SDK
|
|
56
36
|
},
|
|
57
37
|
reddit: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
authUrl: 'https://api2.onairos.uk/reddit/authorize',
|
|
39
|
+
clientId: 'demo_reddit_client_id',
|
|
40
|
+
redirectUri: 'onairosevents://auth/callback',
|
|
41
|
+
scope: 'identity,read',
|
|
42
|
+
responseType: 'code',
|
|
43
|
+
hasNativeSDK: false
|
|
61
44
|
},
|
|
62
45
|
pinterest: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
authUrl: 'https://api2.onairos.uk/pinterest/authorize',
|
|
47
|
+
clientId: 'demo_pinterest_client_id',
|
|
48
|
+
redirectUri: 'onairosevents://auth/callback',
|
|
49
|
+
scope: 'boards:read,pins:read',
|
|
50
|
+
responseType: 'code',
|
|
51
|
+
hasNativeSDK: false
|
|
52
|
+
},
|
|
53
|
+
facebook: {
|
|
54
|
+
authUrl: 'https://www.facebook.com/v12.0/dialog/oauth',
|
|
55
|
+
clientId: 'demo_facebook_client_id',
|
|
56
|
+
redirectUri: 'onairosevents://auth/callback',
|
|
57
|
+
scope: 'public_profile,email',
|
|
58
|
+
responseType: 'code',
|
|
59
|
+
hasNativeSDK: false
|
|
60
|
+
},
|
|
61
|
+
// GitHub connector is temporarily commented out
|
|
62
|
+
// github: {
|
|
63
|
+
// authUrl: 'https://github.com/login/oauth/authorize',
|
|
64
|
+
// clientId: 'demo_github_client_id',
|
|
65
|
+
// redirectUri: 'onairosevents://auth/callback',
|
|
66
|
+
// scope: 'repo,user',
|
|
67
|
+
// responseType: 'code',
|
|
68
|
+
// hasNativeSDK: false
|
|
69
|
+
// },
|
|
70
|
+
linkedin: {
|
|
71
|
+
authUrl: 'https://api2.onairos.uk/linkedin/authorize',
|
|
72
|
+
clientId: '',
|
|
73
|
+
// No client ID needed - backend handles OAuth
|
|
74
|
+
redirectUri: 'onairosevents://auth/callback',
|
|
75
|
+
scope: 'openid profile email',
|
|
76
|
+
// Updated to OpenID Connect scopes as per your backend
|
|
77
|
+
responseType: 'code',
|
|
78
|
+
hasNativeSDK: false // LinkedIn has no modern native SDK
|
|
79
|
+
},
|
|
80
|
+
gmail: {
|
|
81
|
+
authUrl: 'https://api2.onairos.uk/gmail/authorize',
|
|
82
|
+
clientId: 'demo_gmail_client_id',
|
|
83
|
+
redirectUri: 'onairosevents://auth/callback',
|
|
84
|
+
scope: 'https://www.googleapis.com/auth/gmail.readonly',
|
|
85
|
+
responseType: 'code',
|
|
86
|
+
hasNativeSDK: false
|
|
66
87
|
},
|
|
67
88
|
email: {
|
|
89
|
+
// Email doesn't use OAuth but we still need to handle it in the flow
|
|
68
90
|
hasNativeSDK: false,
|
|
69
|
-
|
|
70
|
-
color: '#4285F4'
|
|
91
|
+
authUrl: 'https://api2.onairos.uk/email/authorize' // Proxy endpoint for email verification
|
|
71
92
|
}
|
|
72
93
|
};
|
|
73
94
|
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
95
|
+
/**
|
|
96
|
+
* Check if the platform has a native SDK
|
|
76
97
|
*/
|
|
77
98
|
const hasNativeSDK = platform => {
|
|
78
|
-
|
|
79
|
-
return (
|
|
99
|
+
var _OAUTH_CONFIG$platfor;
|
|
100
|
+
return ((_OAUTH_CONFIG$platfor = OAUTH_CONFIG[platform]) === null || _OAUTH_CONFIG$platfor === void 0 ? void 0 : _OAUTH_CONFIG$platfor.hasNativeSDK) || false;
|
|
80
101
|
};
|
|
81
102
|
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
103
|
+
/**
|
|
104
|
+
* Initiate OAuth flow for a platform
|
|
84
105
|
*/
|
|
85
106
|
exports.hasNativeSDK = hasNativeSDK;
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
107
|
+
const initiateOAuth = async (platform, username) => {
|
|
108
|
+
try {
|
|
109
|
+
console.log(`๐ [OAUTH] Starting OAuth for platform: ${platform}, username: "${username}"`);
|
|
110
|
+
|
|
111
|
+
// Validate username
|
|
112
|
+
if (!username || username.trim() === '') {
|
|
113
|
+
console.error(`โ [OAUTH] Username is required for ${platform} OAuth`);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// For platforms that don't need OAuth (like email), handle differently
|
|
118
|
+
if (platform === 'email') {
|
|
119
|
+
console.log('๐ง [OAUTH] Email platform selected, returning mock auth URL');
|
|
120
|
+
return 'https://api2.onairos.uk/email/authorize?action=verify';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Construct the proxy URL
|
|
124
|
+
const proxyUrl = `https://api2.onairos.uk/${platform}/authorize`;
|
|
125
|
+
console.log(`๐ [OAUTH] Proxy URL: ${proxyUrl}`);
|
|
126
|
+
const requestBody = {
|
|
127
|
+
session: {
|
|
128
|
+
username: username.trim(),
|
|
129
|
+
platform: platform,
|
|
130
|
+
timestamp: new Date().toISOString()
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
console.log(`๐ค [OAUTH] Request body:`, requestBody);
|
|
134
|
+
console.log(`๐ [OAUTH] Headers:`, (0, _api.getApiHeaders)());
|
|
135
|
+
|
|
136
|
+
// Make a POST request to the proxy
|
|
137
|
+
const response = await fetch(proxyUrl, {
|
|
138
|
+
method: 'POST',
|
|
139
|
+
headers: (0, _api.getApiHeaders)(),
|
|
140
|
+
body: JSON.stringify(requestBody)
|
|
141
|
+
});
|
|
142
|
+
console.log(`๐ก [OAUTH] Response status: ${response.status} ${response.statusText}`);
|
|
143
|
+
if (!response.ok) {
|
|
144
|
+
const errorText = await response.text();
|
|
145
|
+
console.error(`โ [OAUTH] Error initiating OAuth for ${platform}: ${response.status} - ${errorText}`);
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const data = await response.json();
|
|
149
|
+
console.log(`๐ [OAUTH] Response data for ${platform}:`, data);
|
|
150
|
+
|
|
151
|
+
// Get the authorization URL from the response
|
|
152
|
+
// Different platforms might use different keys (e.g., pinterestURL, youtubeURL)
|
|
153
|
+
const urlKey = `${platform}URL`;
|
|
154
|
+
const authUrl = data[urlKey] || data.url || null;
|
|
155
|
+
console.log(`๐ [OAUTH] Auth URL for ${platform} (key: ${urlKey}):`, authUrl);
|
|
156
|
+
return authUrl;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(`Error initiating OAuth for ${platform}:`, error);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
89
161
|
};
|
|
90
162
|
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
163
|
+
/**
|
|
164
|
+
* Initialize Google Sign-In configuration with enhanced refresh token support
|
|
165
|
+
* Updated with CRITICAL parameters for refresh token generation
|
|
93
166
|
*/
|
|
94
|
-
exports.
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
167
|
+
exports.initiateOAuth = initiateOAuth;
|
|
168
|
+
const initializeGoogleSignIn = () => {
|
|
169
|
+
_googleSignin.GoogleSignin.configure({
|
|
170
|
+
webClientId: WEB_CLIENT_ID,
|
|
171
|
+
// โ
CRITICAL: Web client ID for refresh tokens
|
|
172
|
+
iosClientId: IOS_CLIENT_ID,
|
|
173
|
+
// โ
iOS client ID for native auth
|
|
174
|
+
|
|
175
|
+
// ๐ CRITICAL: These parameters are REQUIRED for refresh tokens
|
|
176
|
+
offlineAccess: true,
|
|
177
|
+
// โ CRITICAL: Enables refresh tokens
|
|
178
|
+
forceCodeForRefreshToken: true,
|
|
179
|
+
// โ CRITICAL: Forces refresh token generation
|
|
180
|
+
|
|
181
|
+
// โ
Enhanced scopes for YouTube
|
|
182
|
+
scopes: ['https://www.googleapis.com/auth/youtube.readonly', 'openid', 'profile', 'email'],
|
|
183
|
+
// โ
Clear settings to avoid conflicts
|
|
184
|
+
hostedDomain: '',
|
|
185
|
+
accountName: ''
|
|
186
|
+
});
|
|
98
187
|
};
|
|
99
188
|
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @param username The username to associate with the authentication
|
|
104
|
-
* @param appName The app name to use for the OAuth session (optional)
|
|
105
|
-
* @returns A Promise that resolves to the OAuth URL to open in a WebView or null if using native SDK
|
|
189
|
+
/**
|
|
190
|
+
* Force YouTube reconnection with consent screen to get refresh tokens
|
|
191
|
+
* This is the key function to fix YouTube token expiry issues
|
|
106
192
|
*/
|
|
107
|
-
|
|
108
|
-
const initiateOAuth = async (platform, username, appName) => {
|
|
193
|
+
const forceYouTubeReconnectionWithConsent = async username => {
|
|
109
194
|
try {
|
|
110
|
-
|
|
111
|
-
console.log('
|
|
112
|
-
console.log('
|
|
113
|
-
|
|
114
|
-
// Check if the platform is supported
|
|
115
|
-
if (!PLATFORM_AUTH_CONFIG[platform]) {
|
|
116
|
-
console.error('โ Unsupported platform:', platform);
|
|
117
|
-
throw new Error(`Unsupported platform: ${platform}`);
|
|
118
|
-
}
|
|
195
|
+
var _userInfo$data, _userInfo$data2, _userInfo$data3;
|
|
196
|
+
console.log('๐ FORCING fresh YouTube consent for refresh token...');
|
|
197
|
+
console.log('๐ค User:', username);
|
|
119
198
|
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
199
|
+
// Step 1: โ
CRITICAL: Complete sign out (clears all cached consent)
|
|
200
|
+
try {
|
|
201
|
+
await _googleSignin.GoogleSignin.signOut();
|
|
202
|
+
console.log('โ
Signed out - consent cache cleared');
|
|
203
|
+
} catch (signOutError) {
|
|
204
|
+
console.log('โน๏ธ Sign out not needed:', signOutError);
|
|
125
205
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
206
|
+
|
|
207
|
+
// Step 2: โ
CRITICAL: Clear cached tokens if available
|
|
208
|
+
try {
|
|
209
|
+
const existingTokens = await _googleSignin.GoogleSignin.getTokens();
|
|
210
|
+
if (existingTokens.accessToken) {
|
|
211
|
+
await _googleSignin.GoogleSignin.clearCachedAccessToken(existingTokens.accessToken);
|
|
212
|
+
console.log('โ
Token cache cleared');
|
|
213
|
+
}
|
|
214
|
+
} catch (clearError) {
|
|
215
|
+
console.log('โน๏ธ No token cache to clear');
|
|
135
216
|
}
|
|
136
|
-
console.log('โ
Pre-flight connectivity check passed');
|
|
137
217
|
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
218
|
+
// Step 3: โ
CRITICAL: Configure Google Sign-In for FORCED consent
|
|
219
|
+
console.log('๐ง Configuring Google Sign-In for forced consent...');
|
|
220
|
+
_googleSignin.GoogleSignin.configure({
|
|
221
|
+
webClientId: WEB_CLIENT_ID,
|
|
222
|
+
// โ
CRITICAL: Web client ID for refresh tokens
|
|
223
|
+
iosClientId: IOS_CLIENT_ID,
|
|
224
|
+
// โ
iOS client ID for native auth
|
|
225
|
+
|
|
226
|
+
// ๐ FORCE REFRESH TOKEN SETTINGS:
|
|
227
|
+
offlineAccess: true,
|
|
228
|
+
// Request offline access
|
|
229
|
+
forceCodeForRefreshToken: true,
|
|
230
|
+
// Force refresh token generation
|
|
231
|
+
|
|
232
|
+
// ๐ FORCE CONSENT SCREEN:
|
|
233
|
+
scopes: ['https://www.googleapis.com/auth/youtube.readonly', 'openid', 'profile', 'email'],
|
|
234
|
+
// โ
CRITICAL: Clear settings to force fresh consent
|
|
235
|
+
hostedDomain: '',
|
|
236
|
+
accountName: ''
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Step 4: โ
Check Play Services
|
|
240
|
+
await _googleSignin.GoogleSignin.hasPlayServices();
|
|
241
|
+
console.log('โ
Play Services available');
|
|
242
|
+
|
|
243
|
+
// Step 5: โ
CRITICAL: Sign in (this SHOULD show consent screen)
|
|
244
|
+
console.log('๐ Initiating sign-in - consent screen should appear...');
|
|
245
|
+
console.log('๐ฑ User should see: "Allow [App] to access your YouTube account when you\'re not using the app?"');
|
|
246
|
+
const userInfo = await _googleSignin.GoogleSignin.signIn();
|
|
247
|
+
console.log('โ
Sign-in completed - checking for refresh token...');
|
|
248
|
+
console.log('๐ค User email:', (_userInfo$data = userInfo.data) === null || _userInfo$data === void 0 || (_userInfo$data = _userInfo$data.user) === null || _userInfo$data === void 0 ? void 0 : _userInfo$data.email);
|
|
249
|
+
|
|
250
|
+
// Step 6: โ
Get tokens after consent
|
|
251
|
+
const tokens = await _googleSignin.GoogleSignin.getTokens();
|
|
252
|
+
const currentUser = await _googleSignin.GoogleSignin.getCurrentUser();
|
|
253
|
+
console.log('๐ FULL userInfo object from forceYouTubeReconnectionWithConsent:');
|
|
254
|
+
console.log(JSON.stringify(userInfo, null, 2));
|
|
255
|
+
console.log('๐ FULL tokens object from forceYouTubeReconnectionWithConsent:');
|
|
256
|
+
console.log(JSON.stringify(tokens, null, 2));
|
|
257
|
+
console.log('๐ FULL currentUser object from forceYouTubeReconnectionWithConsent:');
|
|
258
|
+
console.log(JSON.stringify(currentUser, null, 2));
|
|
259
|
+
console.log('๐ Token analysis:');
|
|
260
|
+
console.log('- Access token:', tokens.accessToken ? `${tokens.accessToken.substring(0, 20)}...` : 'Missing');
|
|
261
|
+
console.log('- ID token:', tokens.idToken ? 'Present' : 'Missing');
|
|
262
|
+
console.log('- ServerAuthCode (userInfo):', (_userInfo$data2 = userInfo.data) !== null && _userInfo$data2 !== void 0 && _userInfo$data2.serverAuthCode ? `${userInfo.data.serverAuthCode.substring(0, 20)}...` : 'Missing');
|
|
263
|
+
console.log('- ServerAuthCode (currentUser):', currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode ? `${currentUser.serverAuthCode.substring(0, 20)}...` : 'Missing');
|
|
264
|
+
|
|
265
|
+
// Step 7: โ
Extract refresh capability
|
|
266
|
+
const refreshToken = ((_userInfo$data3 = userInfo.data) === null || _userInfo$data3 === void 0 ? void 0 : _userInfo$data3.serverAuthCode) || (currentUser === null || currentUser === void 0 ? void 0 : currentUser.serverAuthCode);
|
|
267
|
+
if (refreshToken) {
|
|
268
|
+
var _userInfo$data0, _userInfo$data1, _userInfo$data10, _userInfo$data11, _userInfo$data12, _userInfo$data13;
|
|
269
|
+
console.log('โ
SUCCESS: Got refresh token after consent!');
|
|
270
|
+
console.log('๐ Refresh token type:', refreshToken.startsWith('4/') ? 'serverAuthCode' : 'refreshToken');
|
|
271
|
+
console.log('๐ Refresh token preview:', `${refreshToken.substring(0, 20)}...`);
|
|
272
|
+
|
|
273
|
+
// Step 8: โ
Get YouTube channel info
|
|
274
|
+
let channelName = 'Unknown Channel';
|
|
275
|
+
let channelId = null;
|
|
276
|
+
try {
|
|
277
|
+
console.log('๐บ Fetching YouTube channel information...');
|
|
278
|
+
const channelResponse = await fetch('https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true', {
|
|
279
|
+
headers: {
|
|
280
|
+
'Authorization': `Bearer ${tokens.accessToken}`,
|
|
281
|
+
'Accept': 'application/json'
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
if (channelResponse.ok) {
|
|
285
|
+
const channelData = await channelResponse.json();
|
|
286
|
+
if (channelData.items && channelData.items.length > 0) {
|
|
287
|
+
channelName = channelData.items[0].snippet.title;
|
|
288
|
+
channelId = channelData.items[0].id;
|
|
289
|
+
console.log('โ
YouTube channel found:', channelName, 'ID:', channelId);
|
|
290
|
+
} else {
|
|
291
|
+
var _userInfo$data4, _userInfo$data5;
|
|
292
|
+
console.log('โ ๏ธ No YouTube channel found for user');
|
|
293
|
+
channelName = ((_userInfo$data4 = userInfo.data) === null || _userInfo$data4 === void 0 || (_userInfo$data4 = _userInfo$data4.user) === null || _userInfo$data4 === void 0 ? void 0 : _userInfo$data4.name) || ((_userInfo$data5 = userInfo.data) === null || _userInfo$data5 === void 0 || (_userInfo$data5 = _userInfo$data5.user) === null || _userInfo$data5 === void 0 ? void 0 : _userInfo$data5.email) || 'No Channel';
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
var _userInfo$data6, _userInfo$data7;
|
|
297
|
+
console.log('โ ๏ธ Failed to fetch YouTube channel info:', channelResponse.status);
|
|
298
|
+
channelName = ((_userInfo$data6 = userInfo.data) === null || _userInfo$data6 === void 0 || (_userInfo$data6 = _userInfo$data6.user) === null || _userInfo$data6 === void 0 ? void 0 : _userInfo$data6.name) || ((_userInfo$data7 = userInfo.data) === null || _userInfo$data7 === void 0 || (_userInfo$data7 = _userInfo$data7.user) === null || _userInfo$data7 === void 0 ? void 0 : _userInfo$data7.email) || 'Unknown Channel';
|
|
299
|
+
}
|
|
300
|
+
} catch (channelError) {
|
|
301
|
+
var _userInfo$data8, _userInfo$data9;
|
|
302
|
+
console.log('โ ๏ธ Error fetching YouTube channel info:', channelError);
|
|
303
|
+
channelName = ((_userInfo$data8 = userInfo.data) === null || _userInfo$data8 === void 0 || (_userInfo$data8 = _userInfo$data8.user) === null || _userInfo$data8 === void 0 ? void 0 : _userInfo$data8.name) || ((_userInfo$data9 = userInfo.data) === null || _userInfo$data9 === void 0 || (_userInfo$data9 = _userInfo$data9.user) === null || _userInfo$data9 === void 0 ? void 0 : _userInfo$data9.email) || 'Unknown Channel';
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Step 9: โ
Get authentication token
|
|
307
|
+
let authToken = (await _asyncStorage.default.getItem('onairos_jwt_token')) || (await _asyncStorage.default.getItem('enoch_token')) || (await _asyncStorage.default.getItem('auth_token'));
|
|
308
|
+
if (!authToken || authToken.trim().length < 20) {
|
|
309
|
+
console.log('๐ Creating authentication token for YouTube connection...');
|
|
310
|
+
// Create token logic here if needed
|
|
311
|
+
authToken = 'temp_token_for_youtube_connection';
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Step 10: โ
Send comprehensive data to backend
|
|
315
|
+
const backendPayload = {
|
|
142
316
|
session: {
|
|
143
|
-
|
|
144
|
-
|
|
317
|
+
username: username,
|
|
318
|
+
platform: 'youtube',
|
|
319
|
+
timestamp: new Date().toISOString(),
|
|
320
|
+
channelName: channelName,
|
|
321
|
+
channelId: channelId,
|
|
322
|
+
forceConsent: true // Flag to indicate this was forced consent
|
|
323
|
+
},
|
|
324
|
+
googleUser: (_userInfo$data0 = userInfo.data) === null || _userInfo$data0 === void 0 ? void 0 : _userInfo$data0.user,
|
|
325
|
+
accessToken: tokens.accessToken,
|
|
326
|
+
idToken: tokens.idToken,
|
|
327
|
+
refreshToken: refreshToken,
|
|
328
|
+
// โ
CRITICAL: The refresh token!
|
|
329
|
+
serverAuthCode: refreshToken,
|
|
330
|
+
// โ
Same as refresh token
|
|
331
|
+
|
|
332
|
+
// โ
CRITICAL: Additional compatibility fields for backend
|
|
333
|
+
refresh_token: refreshToken,
|
|
334
|
+
// Snake case version
|
|
335
|
+
server_auth_code: refreshToken,
|
|
336
|
+
// Snake case version
|
|
337
|
+
authCode: refreshToken,
|
|
338
|
+
// Alternative naming
|
|
339
|
+
|
|
340
|
+
userAccountInfo: {
|
|
341
|
+
username: username,
|
|
342
|
+
email: (_userInfo$data1 = userInfo.data) === null || _userInfo$data1 === void 0 || (_userInfo$data1 = _userInfo$data1.user) === null || _userInfo$data1 === void 0 ? void 0 : _userInfo$data1.email,
|
|
343
|
+
authToken: authToken,
|
|
344
|
+
channelName: channelName,
|
|
345
|
+
channelId: channelId,
|
|
346
|
+
userIdentifier: authToken ? `user-${authToken.substring(0, 10)}` : `youtube-${(_userInfo$data10 = userInfo.data) === null || _userInfo$data10 === void 0 || (_userInfo$data10 = _userInfo$data10.user) === null || _userInfo$data10 === void 0 ? void 0 : _userInfo$data10.email}`,
|
|
347
|
+
googleId: (_userInfo$data11 = userInfo.data) === null || _userInfo$data11 === void 0 || (_userInfo$data11 = _userInfo$data11.user) === null || _userInfo$data11 === void 0 ? void 0 : _userInfo$data11.id,
|
|
348
|
+
// โ
CRITICAL: Also include refresh token in userAccountInfo
|
|
349
|
+
refreshToken: refreshToken,
|
|
350
|
+
serverAuthCode: refreshToken
|
|
351
|
+
},
|
|
352
|
+
tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
|
|
353
|
+
// 1 hour from now
|
|
354
|
+
requestRefreshToken: true,
|
|
355
|
+
debugInfo: {
|
|
356
|
+
hasRefreshToken: true,
|
|
357
|
+
refreshTokenType: refreshToken.startsWith('4/') ? 'serverAuthCode' : 'refreshToken',
|
|
358
|
+
configuredForRefresh: true,
|
|
359
|
+
forcedConsent: true,
|
|
360
|
+
consentMethod: 'signOut_and_configure',
|
|
361
|
+
refreshTokenValue: refreshToken // Include actual value for debugging
|
|
145
362
|
}
|
|
146
363
|
};
|
|
147
|
-
console.log('๐ค Sending
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
364
|
+
console.log('๐ค Sending comprehensive payload with REFRESH TOKEN to backend:', {
|
|
365
|
+
hasAccessToken: !!backendPayload.accessToken,
|
|
366
|
+
hasRefreshToken: !!backendPayload.refreshToken,
|
|
367
|
+
hasServerAuthCode: !!backendPayload.serverAuthCode,
|
|
368
|
+
refreshTokenType: backendPayload.debugInfo.refreshTokenType,
|
|
369
|
+
userEmail: (_userInfo$data12 = userInfo.data) === null || _userInfo$data12 === void 0 || (_userInfo$data12 = _userInfo$data12.user) === null || _userInfo$data12 === void 0 ? void 0 : _userInfo$data12.email,
|
|
370
|
+
forcedConsent: true
|
|
151
371
|
});
|
|
152
|
-
console.log('๐ก Instagram OAuth response status:', response.status);
|
|
153
|
-
if (!response.ok) {
|
|
154
|
-
const errorText = await response.text();
|
|
155
|
-
console.error('โ Instagram OAuth API error:', errorText);
|
|
156
|
-
throw new Error(`Instagram OAuth API error: ${response.status} - ${errorText}`);
|
|
157
|
-
}
|
|
158
|
-
const responseData = await response.json();
|
|
159
|
-
console.log('๐ฅ Instagram OAuth response data:', responseData);
|
|
160
|
-
if (responseData.instagramURL) {
|
|
161
|
-
console.log('โ
Instagram OAuth URL received:', responseData.instagramURL);
|
|
162
372
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
373
|
+
// Step 11: โ
Send to backend with ENHANCED LOGGING
|
|
374
|
+
console.log('๐ [YOUTUBE REAUTH] ===== SENDING REAUTH SIGNAL TO BACKEND =====');
|
|
375
|
+
console.log('๐ [YOUTUBE REAUTH] Endpoint: https://api2.onairos.uk/youtube/native-auth');
|
|
376
|
+
console.log('๐ [YOUTUBE REAUTH] Method: POST');
|
|
377
|
+
console.log('๐ [YOUTUBE REAUTH] Headers:', {
|
|
378
|
+
'Content-Type': 'application/json',
|
|
379
|
+
'Authorization': authToken ? `${authToken.substring(0, 20)}...` : 'NO AUTH TOKEN'
|
|
380
|
+
});
|
|
381
|
+
console.log('๐ [YOUTUBE REAUTH] Payload Summary:', {
|
|
382
|
+
hasAccessToken: !!backendPayload.accessToken,
|
|
383
|
+
hasRefreshToken: !!backendPayload.refreshToken,
|
|
384
|
+
hasServerAuthCode: !!backendPayload.serverAuthCode,
|
|
385
|
+
refreshTokenType: backendPayload.debugInfo.refreshTokenType,
|
|
386
|
+
userEmail: (_userInfo$data13 = userInfo.data) === null || _userInfo$data13 === void 0 || (_userInfo$data13 = _userInfo$data13.user) === null || _userInfo$data13 === void 0 ? void 0 : _userInfo$data13.email,
|
|
387
|
+
channelName: channelName,
|
|
388
|
+
forcedConsent: true,
|
|
389
|
+
requestRefreshToken: true
|
|
390
|
+
});
|
|
391
|
+
console.log('๐ [YOUTUBE REAUTH] FULL PAYLOAD:', JSON.stringify(backendPayload, null, 2));
|
|
392
|
+
const backendResponse = await fetch('https://api2.onairos.uk/youtube/native-auth', {
|
|
393
|
+
method: 'POST',
|
|
394
|
+
headers: {
|
|
395
|
+
'Content-Type': 'application/json',
|
|
396
|
+
...(authToken && {
|
|
397
|
+
'Authorization': authToken
|
|
398
|
+
})
|
|
399
|
+
},
|
|
400
|
+
body: JSON.stringify(backendPayload)
|
|
401
|
+
});
|
|
402
|
+
console.log('๐ก [YOUTUBE REAUTH] Response Status:', backendResponse.status);
|
|
403
|
+
console.log('๐ก [YOUTUBE REAUTH] Response Status Text:', backendResponse.statusText);
|
|
404
|
+
console.log('๐ก [YOUTUBE REAUTH] Response Headers:', backendResponse.headers);
|
|
405
|
+
if (backendResponse.ok) {
|
|
406
|
+
var _responseData$validat, _responseData$tempora;
|
|
407
|
+
const responseData = await backendResponse.json();
|
|
408
|
+
console.log('โ
[YOUTUBE REAUTH] Backend Response SUCCESS:', JSON.stringify(responseData, null, 2));
|
|
409
|
+
|
|
410
|
+
// Enhanced verification with detailed logging and temporary mode detection (exact backend fields)
|
|
411
|
+
const isTemporaryMode = ((_responseData$validat = responseData.validation) === null || _responseData$validat === void 0 ? void 0 : _responseData$validat.isTemporaryMode) === true || ((_responseData$tempora = responseData.temporaryMode) === null || _responseData$tempora === void 0 ? void 0 : _responseData$tempora.enabled) === true || responseData.isTemporaryMode === true || responseData.message && responseData.message.includes('temporary access token mode');
|
|
412
|
+
if (isTemporaryMode) {
|
|
413
|
+
console.log('๐ [YOUTUBE REAUTH] YouTube connected in temporary mode');
|
|
414
|
+
console.log('โ
[YOUTUBE REAUTH] Training will work, but connection expires in ~1 hour');
|
|
415
|
+
console.log('๐ [YOUTUBE REAUTH] SUCCESS: Temporary YouTube connection established!');
|
|
416
|
+
console.log('๐ [YOUTUBE REAUTH] Connection Details:');
|
|
417
|
+
console.log('๐ [YOUTUBE REAUTH] Mode: Temporary (expires ~1 hour)');
|
|
418
|
+
console.log('๐ [YOUTUBE REAUTH] Training Ready: Yes');
|
|
419
|
+
console.log('๐ [YOUTUBE REAUTH] Refresh token sent:', refreshToken ? 'Yes' : 'No');
|
|
420
|
+
} else if (responseData.hasRefreshToken || responseData.refreshTokenReceived) {
|
|
421
|
+
console.log('โ
[YOUTUBE REAUTH] Backend CONFIRMED refresh token received');
|
|
422
|
+
console.log('โ
[YOUTUBE REAUTH] Response hasRefreshToken:', responseData.hasRefreshToken);
|
|
423
|
+
console.log('๐ [YOUTUBE REAUTH] SUCCESS: Full YouTube connection with refresh tokens!');
|
|
424
|
+
|
|
425
|
+
// CRITICAL: Print the refresh token that was sent for debugging
|
|
426
|
+
console.log('๐ [YOUTUBE REAUTH] REFRESH TOKEN SENT TO BACKEND:');
|
|
427
|
+
console.log('๐ [YOUTUBE REAUTH] Full refresh token:', refreshToken);
|
|
428
|
+
console.log('๐ [YOUTUBE REAUTH] Refresh token type:', refreshToken.startsWith('4/') ? 'serverAuthCode' : 'refreshToken');
|
|
429
|
+
console.log('๐ [YOUTUBE REAUTH] Refresh token length:', refreshToken.length);
|
|
166
430
|
} else {
|
|
167
|
-
|
|
431
|
+
console.warn('โ ๏ธ [YOUTUBE REAUTH] Backend did NOT confirm refresh token reception');
|
|
432
|
+
console.warn('โ ๏ธ [YOUTUBE REAUTH] Response data:', responseData);
|
|
433
|
+
console.warn('โ ๏ธ [YOUTUBE REAUTH] Expected hasRefreshToken or refreshTokenReceived in response');
|
|
434
|
+
return false;
|
|
168
435
|
}
|
|
436
|
+
|
|
437
|
+
// CRITICAL: Signal training system to restart with new connection
|
|
438
|
+
console.log('๐ [YOUTUBE REAUTH] Signaling training system to restart...');
|
|
439
|
+
try {
|
|
440
|
+
await triggerTrainingRestart(username, authToken);
|
|
441
|
+
console.log('โ
[YOUTUBE REAUTH] Training restart signal sent successfully');
|
|
442
|
+
} catch (restartError) {
|
|
443
|
+
console.warn('โ ๏ธ [YOUTUBE REAUTH] Training restart signal failed:', restartError);
|
|
444
|
+
console.warn('โ ๏ธ [YOUTUBE REAUTH] User may need to manually restart training');
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
} else {
|
|
448
|
+
const errorData = await backendResponse.text();
|
|
449
|
+
console.error('โ [YOUTUBE REAUTH] Backend processing FAILED:', backendResponse.status, errorData);
|
|
450
|
+
console.error('โ [YOUTUBE REAUTH] This means the reauth signal was not processed');
|
|
451
|
+
return false;
|
|
169
452
|
}
|
|
170
|
-
|
|
171
|
-
|
|
453
|
+
} else {
|
|
454
|
+
console.error('โ CRITICAL: No refresh token even after consent screen');
|
|
455
|
+
console.error('โ This means consent screen did not appear or user denied permissions');
|
|
456
|
+
console.error('๐ก Solutions:');
|
|
457
|
+
console.error(' 1. Try the revoke method: forceYouTubeReconnectionWithRevoke()');
|
|
458
|
+
console.error(' 2. Check Google Console OAuth configuration');
|
|
459
|
+
console.error(' 3. Ensure user clicks "Allow" on consent screen');
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
} catch (error) {
|
|
463
|
+
console.error('โ Error forcing YouTube consent:', error);
|
|
464
|
+
if (error.code === _googleSignin.statusCodes.SIGN_IN_CANCELLED) {
|
|
465
|
+
console.error('โ User cancelled sign-in - no refresh token obtained');
|
|
466
|
+
console.error('๐ก User must click "Allow" to get refresh token');
|
|
467
|
+
} else if (error.code === _googleSignin.statusCodes.IN_PROGRESS) {
|
|
468
|
+
console.error('โ Sign-in already in progress');
|
|
469
|
+
} else if (error.code === _googleSignin.statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
|
|
470
|
+
console.error('โ Google Play Services not available');
|
|
172
471
|
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
173
475
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
console.log(`๐ค Sending ${platform} OAuth request:`, jsonData);
|
|
476
|
+
/**
|
|
477
|
+
* Alternative method: Force consent by revoking existing permissions
|
|
478
|
+
*/
|
|
479
|
+
exports.forceYouTubeReconnectionWithConsent = forceYouTubeReconnectionWithConsent;
|
|
480
|
+
const forceYouTubeReconnectionWithRevoke = async username => {
|
|
481
|
+
try {
|
|
482
|
+
var _userInfo$data14;
|
|
483
|
+
console.log('๐ FORCING YouTube consent via REVOKE method...');
|
|
484
|
+
console.log('๐ค User:', username);
|
|
184
485
|
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
486
|
+
// Step 1: Initialize Google Sign-In
|
|
487
|
+
initializeGoogleSignIn();
|
|
488
|
+
await _googleSignin.GoogleSignin.hasPlayServices();
|
|
489
|
+
|
|
490
|
+
// Step 2: โ
CRITICAL: Revoke existing permissions (forces fresh consent)
|
|
491
|
+
try {
|
|
492
|
+
await _googleSignin.GoogleSignin.revokeAccess();
|
|
493
|
+
console.log('โ
Revoked existing permissions - fresh consent REQUIRED');
|
|
494
|
+
} catch (revokeError) {
|
|
495
|
+
console.log('โน๏ธ No existing permissions to revoke:', revokeError);
|
|
195
496
|
}
|
|
196
497
|
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
console.log(
|
|
498
|
+
// Step 3: Sign out completely
|
|
499
|
+
await _googleSignin.GoogleSignin.signOut();
|
|
500
|
+
console.log('โ
Signed out completely');
|
|
200
501
|
|
|
201
|
-
//
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
console.log('๐ Gmail OAuth full response:', JSON.stringify(data, null, 2));
|
|
205
|
-
}
|
|
502
|
+
// Step 4: โ
Now sign in again (will DEFINITELY show consent screen)
|
|
503
|
+
console.log('๐ Signing in after revoke - consent screen MUST appear...');
|
|
504
|
+
const userInfo = await _googleSignin.GoogleSignin.signIn();
|
|
206
505
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
oauthUrl = data.youtubeURL;
|
|
218
|
-
break;
|
|
219
|
-
case 'email':
|
|
220
|
-
// Gmail might return under different field names
|
|
221
|
-
oauthUrl = data.emailURL || data.gmailURL || data.authUrl || data.url;
|
|
222
|
-
break;
|
|
223
|
-
default:
|
|
224
|
-
oauthUrl = data.url;
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
if (!oauthUrl) {
|
|
228
|
-
console.error(`โ No OAuth URL found in response for ${platform}. Response:`, data);
|
|
229
|
-
throw new Error(`No OAuth URL found in response for ${platform}`);
|
|
230
|
-
}
|
|
231
|
-
console.log(`โ
${platform} OAuth URL received:`, oauthUrl);
|
|
506
|
+
// Step 5: โ
User will definitely see consent screen now
|
|
507
|
+
const tokens = await _googleSignin.GoogleSignin.getTokens();
|
|
508
|
+
const currentUser = await _googleSignin.GoogleSignin.getCurrentUser();
|
|
509
|
+
const refreshToken = ((_userInfo$data14 = userInfo.data) === null || _userInfo$data14 === void 0 ? void 0 : _userInfo$data14.serverAuthCode) || (currentUser === null || currentUser === void 0 ? void 0 : currentUser.serverAuthCode);
|
|
510
|
+
if (refreshToken) {
|
|
511
|
+
console.log('โ
SUCCESS: Got refresh token after REVOKE + consent!');
|
|
512
|
+
console.log('๐ Refresh token preview:', `${refreshToken.substring(0, 20)}...`);
|
|
513
|
+
|
|
514
|
+
// Continue with the same backend submission logic as above
|
|
515
|
+
// (Similar to forceYouTubeReconnectionWithConsent)
|
|
232
516
|
|
|
233
|
-
|
|
234
|
-
if (await validateOAuthUrl(oauthUrl)) {
|
|
235
|
-
return oauthUrl;
|
|
517
|
+
return true;
|
|
236
518
|
} else {
|
|
237
|
-
|
|
519
|
+
console.error('โ Still no refresh token after revoke method');
|
|
520
|
+
return false;
|
|
238
521
|
}
|
|
239
522
|
} catch (error) {
|
|
240
|
-
console.error(
|
|
241
|
-
|
|
523
|
+
console.error('โ Error with revoke method:', error);
|
|
524
|
+
return false;
|
|
242
525
|
}
|
|
243
526
|
};
|
|
244
527
|
|
|
245
|
-
/**
|
|
246
|
-
*
|
|
247
|
-
* @param url The OAuth URL to validate
|
|
248
|
-
* @returns Promise<boolean> indicating if the URL is valid and reachable
|
|
528
|
+
/**
|
|
529
|
+
* Fix YouTube connection for a specific user (like nicholase50)
|
|
249
530
|
*/
|
|
250
|
-
exports.
|
|
251
|
-
const
|
|
531
|
+
exports.forceYouTubeReconnectionWithRevoke = forceYouTubeReconnectionWithRevoke;
|
|
532
|
+
const fixUserYouTubeConnection = async username => {
|
|
533
|
+
console.log(`๐ง Fixing YouTube connection for user: ${username}`);
|
|
534
|
+
|
|
535
|
+
// Method 1: Try forced consent via configuration
|
|
536
|
+
console.log('๐ Method 1: Trying forced consent via configuration...');
|
|
537
|
+
let success = await forceYouTubeReconnectionWithConsent(username);
|
|
538
|
+
if (success) {
|
|
539
|
+
console.log(`โ
${username} YouTube connection fixed via Method 1!`);
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// Method 2: Try forced consent via revoke
|
|
544
|
+
console.log('๐ Method 2: Trying forced consent via revoke...');
|
|
545
|
+
success = await forceYouTubeReconnectionWithRevoke(username);
|
|
546
|
+
if (success) {
|
|
547
|
+
console.log(`โ
${username} YouTube connection fixed via Method 2!`);
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
console.error(`โ Failed to fix ${username} YouTube connection with both methods`);
|
|
551
|
+
return false;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Get fresh tokens using refresh token
|
|
556
|
+
*/
|
|
557
|
+
exports.fixUserYouTubeConnection = fixUserYouTubeConnection;
|
|
558
|
+
const refreshGoogleTokens = async () => {
|
|
252
559
|
try {
|
|
253
|
-
console.log('
|
|
560
|
+
console.log('๐ Attempting to refresh Google tokens...');
|
|
254
561
|
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
562
|
+
// Check if user is signed in
|
|
563
|
+
const currentUser = await _googleSignin.GoogleSignin.getCurrentUser();
|
|
564
|
+
if (!currentUser) {
|
|
565
|
+
console.log('โ User not signed in to Google, cannot refresh tokens');
|
|
566
|
+
return null;
|
|
259
567
|
}
|
|
260
568
|
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
569
|
+
// Get fresh tokens
|
|
570
|
+
const tokens = await _googleSignin.GoogleSignin.getTokens();
|
|
571
|
+
console.log('โ
Successfully refreshed Google tokens');
|
|
572
|
+
return {
|
|
573
|
+
accessToken: tokens.accessToken,
|
|
574
|
+
idToken: tokens.idToken
|
|
575
|
+
};
|
|
576
|
+
} catch (error) {
|
|
577
|
+
console.error('โ Failed to refresh Google tokens:', error);
|
|
266
578
|
|
|
267
|
-
//
|
|
579
|
+
// If refresh fails, try to sign in again
|
|
268
580
|
try {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
581
|
+
console.log('๐ Refresh failed, attempting re-authentication...');
|
|
582
|
+
const userInfo = await _googleSignin.GoogleSignin.signIn();
|
|
583
|
+
const tokens = await _googleSignin.GoogleSignin.getTokens();
|
|
584
|
+
console.log('โ
Re-authentication successful');
|
|
585
|
+
return {
|
|
586
|
+
accessToken: tokens.accessToken,
|
|
587
|
+
idToken: tokens.idToken
|
|
588
|
+
};
|
|
589
|
+
} catch (signInError) {
|
|
590
|
+
console.error('โ Re-authentication also failed:', signInError);
|
|
591
|
+
return null;
|
|
273
592
|
}
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Debug YouTube tokens to verify refresh token availability
|
|
598
|
+
*/
|
|
599
|
+
const debugYouTubeTokens = async () => {
|
|
600
|
+
try {
|
|
601
|
+
var _currentUser$user;
|
|
602
|
+
const tokens = await _googleSignin.GoogleSignin.getTokens();
|
|
603
|
+
const currentUser = await _googleSignin.GoogleSignin.getCurrentUser();
|
|
604
|
+
console.log('๐ YouTube Token Debug:', {
|
|
605
|
+
accessToken: tokens.accessToken ? `${tokens.accessToken.substring(0, 20)}...` : 'Missing',
|
|
606
|
+
idToken: tokens.idToken ? 'Present' : 'Missing',
|
|
607
|
+
serverAuthCode: currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode ? `${currentUser.serverAuthCode.substring(0, 20)}...` : 'Missing',
|
|
608
|
+
userEmail: (currentUser === null || currentUser === void 0 || (_currentUser$user = currentUser.user) === null || _currentUser$user === void 0 ? void 0 : _currentUser$user.email) || 'Missing'
|
|
609
|
+
});
|
|
610
|
+
return {
|
|
611
|
+
hasRefreshToken: !!(currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode),
|
|
612
|
+
refreshTokenType: currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode ? 'serverAuthCode' : 'none'
|
|
613
|
+
};
|
|
614
|
+
} catch (error) {
|
|
615
|
+
console.error('โ Debug tokens failed:', error);
|
|
616
|
+
return {
|
|
617
|
+
hasRefreshToken: false,
|
|
618
|
+
refreshTokenType: 'error'
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
};
|
|
274
622
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
623
|
+
/**
|
|
624
|
+
* Force fresh YouTube reconnection with proper refresh token
|
|
625
|
+
*/
|
|
626
|
+
const reconnectYouTube = async username => {
|
|
627
|
+
try {
|
|
628
|
+
console.log('๐ Forcing fresh YouTube reconnection for refresh token...');
|
|
278
629
|
|
|
630
|
+
// 1. Sign out completely to force fresh consent
|
|
279
631
|
try {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
632
|
+
await _googleSignin.GoogleSignin.signOut();
|
|
633
|
+
console.log('โ
Signed out from Google');
|
|
634
|
+
} catch (signOutError) {
|
|
635
|
+
console.log('โน๏ธ Already signed out or sign out failed:', signOutError);
|
|
636
|
+
}
|
|
285
637
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (fetchError.name === 'AbortError') {
|
|
293
|
-
console.warn('โ ๏ธ OAuth URL validation timeout, but proceeding anyway');
|
|
294
|
-
return true; // Allow timeout as URLs might be slow to respond
|
|
638
|
+
// 2. Clear any cached tokens
|
|
639
|
+
try {
|
|
640
|
+
const currentTokens = await _googleSignin.GoogleSignin.getTokens();
|
|
641
|
+
if (currentTokens.accessToken) {
|
|
642
|
+
await _googleSignin.GoogleSignin.clearCachedAccessToken(currentTokens.accessToken);
|
|
643
|
+
console.log('โ
Cleared cached access token');
|
|
295
644
|
}
|
|
296
|
-
|
|
297
|
-
|
|
645
|
+
} catch (clearError) {
|
|
646
|
+
console.log('โน๏ธ Token clearing failed or not needed:', clearError);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// 3. Re-authenticate with fresh consent
|
|
650
|
+
const result = await initiateNativeAuth('youtube', username);
|
|
651
|
+
if (result) {
|
|
652
|
+
console.log('โ
YouTube reconnected successfully with refresh token');
|
|
653
|
+
|
|
654
|
+
// 4. Verify we now have a refresh token
|
|
655
|
+
const debugInfo = await debugYouTubeTokens();
|
|
656
|
+
if (debugInfo.hasRefreshToken) {
|
|
657
|
+
console.log('โ
Refresh token confirmed:', debugInfo.refreshTokenType);
|
|
658
|
+
} else {
|
|
659
|
+
console.warn('โ ๏ธ Still no refresh token after reconnection');
|
|
660
|
+
}
|
|
661
|
+
return true;
|
|
662
|
+
} else {
|
|
663
|
+
console.error('โ YouTube reconnection failed');
|
|
664
|
+
return false;
|
|
298
665
|
}
|
|
299
666
|
} catch (error) {
|
|
300
|
-
console.
|
|
301
|
-
return
|
|
667
|
+
console.error('โ YouTube reconnection error:', error);
|
|
668
|
+
return false;
|
|
302
669
|
}
|
|
303
670
|
};
|
|
304
671
|
|
|
305
|
-
/**
|
|
306
|
-
*
|
|
307
|
-
* @param platform The platform to authenticate with
|
|
308
|
-
* @returns A Promise that resolves to the authentication result
|
|
672
|
+
/**
|
|
673
|
+
* Initiate native authentication for platforms with SDKs
|
|
309
674
|
*/
|
|
675
|
+
exports.reconnectYouTube = reconnectYouTube;
|
|
310
676
|
const initiateNativeAuth = async (platform, username) => {
|
|
311
677
|
if (platform === 'youtube') {
|
|
312
678
|
console.log('๐ Initiating native Google Sign-In for YouTube');
|
|
679
|
+
|
|
680
|
+
// Validate username for YouTube
|
|
681
|
+
if (!username || username.trim() === '') {
|
|
682
|
+
console.error('โ [YOUTUBE AUTH] Username is required for YouTube authentication');
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
313
685
|
try {
|
|
314
|
-
var _currentUser$
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const googleSignInModule = require('@react-native-google-signin/google-signin');
|
|
319
|
-
GoogleSignin = googleSignInModule.GoogleSignin;
|
|
320
|
-
statusCodes = googleSignInModule.statusCodes;
|
|
321
|
-
} catch (importError) {
|
|
322
|
-
console.error('โ Google Sign-In package not available:', importError);
|
|
323
|
-
throw new Error('Google Sign-In SDK not installed. Please install @react-native-google-signin/google-signin');
|
|
324
|
-
}
|
|
686
|
+
var _userInfo$data15, _currentUser$user2, _userInfo$data16, _userInfo$data17, _userInfo$data24, _userInfo$data27, _userInfo$data28, _userInfo$data29, _userInfo$data30, _authToken, _userInfo$data31;
|
|
687
|
+
// Initialize Google Sign-In if not already done
|
|
688
|
+
// โ
CRITICAL: Initialize with CORRECT iOS Client ID
|
|
689
|
+
initializeGoogleSignIn();
|
|
325
690
|
|
|
326
|
-
//
|
|
327
|
-
|
|
328
|
-
const youtubeConfig = PLATFORM_AUTH_CONFIG.youtube;
|
|
329
|
-
const webClientId = youtubeConfig.clientId || '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com';
|
|
330
|
-
const iosClientId = youtubeConfig.iosClientId || webClientId;
|
|
331
|
-
await GoogleSignin.configure({
|
|
332
|
-
webClientId: webClientId,
|
|
333
|
-
iosClientId: iosClientId,
|
|
334
|
-
scopes: ['https://www.googleapis.com/auth/youtube.readonly'],
|
|
335
|
-
offlineAccess: true,
|
|
336
|
-
hostedDomain: '',
|
|
337
|
-
forceCodeForRefreshToken: true,
|
|
338
|
-
accountName: ''
|
|
339
|
-
});
|
|
340
|
-
console.log('โ
Google Sign-In configured successfully with client ID:', webClientId.substring(0, 20) + '...');
|
|
341
|
-
} catch (configError) {
|
|
342
|
-
console.error('โ Google Sign-In configuration failed:', configError);
|
|
343
|
-
throw new Error(`Google Sign-In configuration failed: ${configError.message || configError}`);
|
|
344
|
-
}
|
|
691
|
+
// Check if Google Play Services are available
|
|
692
|
+
await _googleSignin.GoogleSignin.hasPlayServices();
|
|
345
693
|
|
|
346
|
-
//
|
|
694
|
+
// โ
CRITICAL: Force sign out first to ensure fresh consent
|
|
347
695
|
try {
|
|
348
|
-
await GoogleSignin.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
console.log('
|
|
352
|
-
} catch (playServicesError) {
|
|
353
|
-
console.error('โ Google Play Services error:', playServicesError);
|
|
354
|
-
throw new Error(`Google Play Services not available: ${playServicesError.message || playServicesError}`);
|
|
696
|
+
await _googleSignin.GoogleSignin.signOut();
|
|
697
|
+
console.log('๐ Signed out to force fresh consent');
|
|
698
|
+
} catch (signOutError) {
|
|
699
|
+
console.log('โน๏ธ Sign out not needed or failed:', signOutError);
|
|
355
700
|
}
|
|
356
701
|
|
|
357
|
-
// Sign in with Google
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
console.log('โ
Google Sign-In successful:', (_userInfo$user = userInfo.user) === null || _userInfo$user === void 0 ? void 0 : _userInfo$user.email);
|
|
363
|
-
} catch (signInError) {
|
|
364
|
-
console.error('โ Google Sign-In failed:', signInError);
|
|
365
|
-
|
|
366
|
-
// Handle specific error codes
|
|
367
|
-
if (signInError.code === statusCodes.SIGN_IN_CANCELLED) {
|
|
368
|
-
throw new Error('Google Sign-In was cancelled by user');
|
|
369
|
-
} else if (signInError.code === statusCodes.IN_PROGRESS) {
|
|
370
|
-
throw new Error('Google Sign-In already in progress');
|
|
371
|
-
} else if (signInError.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
|
|
372
|
-
throw new Error('Google Play Services not available or outdated');
|
|
373
|
-
} else {
|
|
374
|
-
throw new Error(`Google Sign-In failed: ${signInError.message || signInError}`);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
702
|
+
// Sign in with Google (this will show consent screen due to our config)
|
|
703
|
+
const userInfo = await _googleSignin.GoogleSignin.signIn();
|
|
704
|
+
console.log('โ
Google Sign-In successful:', (_userInfo$data15 = userInfo.data) === null || _userInfo$data15 === void 0 || (_userInfo$data15 = _userInfo$data15.user) === null || _userInfo$data15 === void 0 ? void 0 : _userInfo$data15.email);
|
|
705
|
+
console.log('๐ FULL userInfo object:');
|
|
706
|
+
console.log(JSON.stringify(userInfo, null, 2));
|
|
377
707
|
|
|
378
708
|
// Get access token for API calls
|
|
379
|
-
const tokens = await GoogleSignin.getTokens();
|
|
709
|
+
const tokens = await _googleSignin.GoogleSignin.getTokens();
|
|
380
710
|
console.log('๐ Got Google tokens');
|
|
711
|
+
console.log('๐ FULL tokens object:');
|
|
712
|
+
console.log(JSON.stringify(tokens, null, 2));
|
|
381
713
|
|
|
382
|
-
// Get current user info
|
|
383
|
-
const currentUser = await GoogleSignin.getCurrentUser();
|
|
384
|
-
console.log('๐ค Current user info:', currentUser === null || currentUser === void 0 || (_currentUser$
|
|
714
|
+
// CRITICAL: Get the current user info which contains the refresh token
|
|
715
|
+
const currentUser = await _googleSignin.GoogleSignin.getCurrentUser();
|
|
716
|
+
console.log('๐ค Current user info:', currentUser === null || currentUser === void 0 || (_currentUser$user2 = currentUser.user) === null || _currentUser$user2 === void 0 ? void 0 : _currentUser$user2.email);
|
|
717
|
+
console.log('๐ FULL currentUser object:');
|
|
718
|
+
console.log(JSON.stringify(currentUser, null, 2));
|
|
385
719
|
|
|
386
|
-
// Extract refresh token
|
|
720
|
+
// โ
CRITICAL: Extract refresh token properly using serverAuthCode
|
|
387
721
|
let refreshToken = null;
|
|
722
|
+
console.log('๐ REFRESH TOKEN EXTRACTION:');
|
|
723
|
+
console.log('- userInfo.data?.serverAuthCode:', (_userInfo$data16 = userInfo.data) !== null && _userInfo$data16 !== void 0 && _userInfo$data16.serverAuthCode ? `Present: ${userInfo.data.serverAuthCode.substring(0, 20)}...` : 'Missing');
|
|
724
|
+
console.log('- currentUser?.serverAuthCode:', currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode ? `Present: ${currentUser.serverAuthCode.substring(0, 20)}...` : 'Missing');
|
|
725
|
+
console.log('- tokens.idToken:', tokens.idToken ? `Present: ${tokens.idToken.substring(0, 20)}...` : 'Missing');
|
|
726
|
+
console.log('- tokens.accessToken:', tokens.accessToken ? `Present: ${tokens.accessToken.substring(0, 20)}...` : 'Missing');
|
|
727
|
+
|
|
728
|
+
// The serverAuthCode is the refresh token mechanism for React Native Google Sign-In
|
|
388
729
|
if (currentUser !== null && currentUser !== void 0 && currentUser.serverAuthCode) {
|
|
389
|
-
console.log('๐ Server auth code available for refresh token');
|
|
390
730
|
refreshToken = currentUser.serverAuthCode;
|
|
731
|
+
console.log('โ
Got serverAuthCode (refresh token mechanism)');
|
|
732
|
+
console.log('๐ Refresh token preview:', `${refreshToken.substring(0, 20)}...`);
|
|
733
|
+
} else if ((_userInfo$data17 = userInfo.data) !== null && _userInfo$data17 !== void 0 && _userInfo$data17.serverAuthCode) {
|
|
734
|
+
refreshToken = userInfo.data.serverAuthCode;
|
|
735
|
+
console.log('โ
Got serverAuthCode from sign-in response');
|
|
736
|
+
console.log('๐ Refresh token preview:', `${refreshToken.substring(0, 20)}...`);
|
|
391
737
|
}
|
|
738
|
+
|
|
739
|
+
// โ
CRITICAL: Verify refresh token availability
|
|
392
740
|
if (!refreshToken) {
|
|
393
|
-
console.
|
|
741
|
+
console.error('โ CRITICAL: No refresh token available - YouTube connection will fail when token expires');
|
|
742
|
+
console.error('๐ก User needs to reconnect with proper consent screen');
|
|
743
|
+
console.error('๐ก Check Google Sign-In configuration: offlineAccess, forceCodeForRefreshToken');
|
|
744
|
+
|
|
745
|
+
// Still continue but warn about the issue
|
|
746
|
+
console.warn('โ ๏ธ Continuing without refresh token - connection may fail later');
|
|
394
747
|
} else {
|
|
395
748
|
console.log('โ
Refresh token available for YouTube connection');
|
|
749
|
+
console.log('๐ Refresh token type:', refreshToken.startsWith('4/') ? 'serverAuthCode' : 'refreshToken');
|
|
396
750
|
}
|
|
397
751
|
|
|
398
|
-
// Fetch YouTube channel information
|
|
752
|
+
// Fetch YouTube channel information using the access token
|
|
399
753
|
let channelName = 'Unknown Channel';
|
|
400
754
|
let channelId = null;
|
|
401
755
|
try {
|
|
@@ -411,28 +765,60 @@ const initiateNativeAuth = async (platform, username) => {
|
|
|
411
765
|
if (channelData.items && channelData.items.length > 0) {
|
|
412
766
|
channelName = channelData.items[0].snippet.title;
|
|
413
767
|
channelId = channelData.items[0].id;
|
|
414
|
-
console.log('โ
YouTube channel found:', channelName);
|
|
768
|
+
console.log('โ
YouTube channel found:', channelName, 'ID:', channelId);
|
|
769
|
+
} else {
|
|
770
|
+
var _userInfo$data18, _userInfo$data19;
|
|
771
|
+
console.log('โ ๏ธ No YouTube channel found for user');
|
|
772
|
+
channelName = ((_userInfo$data18 = userInfo.data) === null || _userInfo$data18 === void 0 || (_userInfo$data18 = _userInfo$data18.user) === null || _userInfo$data18 === void 0 ? void 0 : _userInfo$data18.name) || ((_userInfo$data19 = userInfo.data) === null || _userInfo$data19 === void 0 || (_userInfo$data19 = _userInfo$data19.user) === null || _userInfo$data19 === void 0 ? void 0 : _userInfo$data19.email) || 'No Channel';
|
|
415
773
|
}
|
|
774
|
+
} else {
|
|
775
|
+
var _userInfo$data20, _userInfo$data21;
|
|
776
|
+
console.log('โ ๏ธ Failed to fetch YouTube channel info:', channelResponse.status);
|
|
777
|
+
channelName = ((_userInfo$data20 = userInfo.data) === null || _userInfo$data20 === void 0 || (_userInfo$data20 = _userInfo$data20.user) === null || _userInfo$data20 === void 0 ? void 0 : _userInfo$data20.name) || ((_userInfo$data21 = userInfo.data) === null || _userInfo$data21 === void 0 || (_userInfo$data21 = _userInfo$data21.user) === null || _userInfo$data21 === void 0 ? void 0 : _userInfo$data21.email) || 'Unknown Channel';
|
|
416
778
|
}
|
|
417
779
|
} catch (channelError) {
|
|
418
|
-
var _userInfo$
|
|
780
|
+
var _userInfo$data22, _userInfo$data23;
|
|
419
781
|
console.log('โ ๏ธ Error fetching YouTube channel info:', channelError);
|
|
420
|
-
channelName = ((_userInfo$
|
|
782
|
+
channelName = ((_userInfo$data22 = userInfo.data) === null || _userInfo$data22 === void 0 || (_userInfo$data22 = _userInfo$data22.user) === null || _userInfo$data22 === void 0 ? void 0 : _userInfo$data22.name) || ((_userInfo$data23 = userInfo.data) === null || _userInfo$data23 === void 0 || (_userInfo$data23 = _userInfo$data23.user) === null || _userInfo$data23 === void 0 ? void 0 : _userInfo$data23.email) || 'Unknown Channel';
|
|
421
783
|
}
|
|
422
784
|
|
|
423
|
-
// Get authentication info
|
|
785
|
+
// Get stored authentication info to link YouTube data to user account
|
|
424
786
|
let authToken = (await _asyncStorage.default.getItem('onairos_jwt_token')) || (await _asyncStorage.default.getItem('enoch_token')) || (await _asyncStorage.default.getItem('auth_token'));
|
|
425
787
|
const storedUsername = await _asyncStorage.default.getItem('onairos_username');
|
|
426
|
-
const finalUsername = storedUsername || username || ((_userInfo$
|
|
788
|
+
const finalUsername = storedUsername || username || ((_userInfo$data24 = userInfo.data) === null || _userInfo$data24 === void 0 || (_userInfo$data24 = _userInfo$data24.user) === null || _userInfo$data24 === void 0 ? void 0 : _userInfo$data24.email) || 'youtube_user';
|
|
427
789
|
|
|
428
|
-
//
|
|
790
|
+
// If no auth token exists, create one now to ensure YouTube data is linked to user account
|
|
429
791
|
if (!authToken || authToken.trim().length < 20) {
|
|
430
|
-
console.log('๐
|
|
792
|
+
console.log('๐ No valid authentication token found, creating one for YouTube authentication...');
|
|
431
793
|
try {
|
|
432
|
-
var _userInfo$
|
|
433
|
-
|
|
794
|
+
var _userInfo$data25;
|
|
795
|
+
// Create user accounts and get proper Enoch token
|
|
796
|
+
const fallbackEmail = ((_userInfo$data25 = userInfo.data) === null || _userInfo$data25 === void 0 || (_userInfo$data25 = _userInfo$data25.user) === null || _userInfo$data25 === void 0 ? void 0 : _userInfo$data25.email) || `${finalUsername}@youtube.temp`;
|
|
797
|
+
|
|
798
|
+
// Step 1: Create Enoch user first
|
|
799
|
+
console.log('๐ Step 1: Creating Enoch user for YouTube auth...');
|
|
800
|
+
try {
|
|
801
|
+
var _userInfo$data26;
|
|
802
|
+
const enochRegisterResponse = await fetch('https://api2.onairos.uk/enoch/users/register', {
|
|
803
|
+
method: 'POST',
|
|
804
|
+
headers: {
|
|
805
|
+
'Content-Type': 'application/json'
|
|
806
|
+
},
|
|
807
|
+
body: JSON.stringify({
|
|
808
|
+
email: fallbackEmail,
|
|
809
|
+
name: finalUsername,
|
|
810
|
+
photoUrl: ((_userInfo$data26 = userInfo.data) === null || _userInfo$data26 === void 0 || (_userInfo$data26 = _userInfo$data26.user) === null || _userInfo$data26 === void 0 ? void 0 : _userInfo$data26.photo) || ''
|
|
811
|
+
})
|
|
812
|
+
});
|
|
813
|
+
console.log('๐ก Enoch register response status:', enochRegisterResponse.status);
|
|
814
|
+
const enochResponseData = await enochRegisterResponse.json();
|
|
815
|
+
console.log('๐ Enoch user creation response:', enochResponseData);
|
|
816
|
+
} catch (enochError) {
|
|
817
|
+
console.warn('โ ๏ธ Enoch user creation failed (continuing):', enochError);
|
|
818
|
+
}
|
|
434
819
|
|
|
435
|
-
// Create
|
|
820
|
+
// Step 2: Create Onairos account to get JWT token
|
|
821
|
+
console.log('๐ Step 2: Creating Onairos account for YouTube auth...');
|
|
436
822
|
const onairosSignupResponse = await fetch('https://api2.onairos.uk/register/enoch', {
|
|
437
823
|
method: 'POST',
|
|
438
824
|
headers: {
|
|
@@ -444,255 +830,248 @@ const initiateNativeAuth = async (platform, username) => {
|
|
|
444
830
|
name: finalUsername
|
|
445
831
|
})
|
|
446
832
|
});
|
|
833
|
+
console.log('๐ก Onairos register response status:', onairosSignupResponse.status);
|
|
447
834
|
if (onairosSignupResponse.ok) {
|
|
448
835
|
var _onairosResponseData$;
|
|
449
836
|
const onairosResponseData = await onairosSignupResponse.json();
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
837
|
+
console.log('๐ Onairos account creation response:', onairosResponseData);
|
|
838
|
+
|
|
839
|
+
// Extract the token from the response
|
|
840
|
+
if (onairosResponseData.token) {
|
|
841
|
+
authToken = onairosResponseData.token;
|
|
842
|
+
} else if ((_onairosResponseData$ = onairosResponseData.data) !== null && _onairosResponseData$ !== void 0 && _onairosResponseData$.token) {
|
|
843
|
+
authToken = onairosResponseData.data.token;
|
|
844
|
+
} else if (onairosResponseData.jwt) {
|
|
845
|
+
authToken = onairosResponseData.jwt;
|
|
846
|
+
}
|
|
453
847
|
if (authToken) {
|
|
454
|
-
// Store
|
|
848
|
+
// Store the Enoch token in all the standard locations
|
|
455
849
|
await _asyncStorage.default.setItem('onairos_jwt_token', authToken);
|
|
456
850
|
await _asyncStorage.default.setItem('enoch_token', authToken);
|
|
457
851
|
await _asyncStorage.default.setItem('auth_token', authToken);
|
|
458
852
|
await _asyncStorage.default.setItem('onairos_username', onairosResponseData.username || finalUsername);
|
|
459
|
-
console.log('โ
Successfully created and stored authentication token');
|
|
853
|
+
console.log('โ
Successfully created and stored Enoch authentication token for YouTube');
|
|
854
|
+
console.log('๐ Enoch token preview:', `${authToken.substring(0, 20)}...`);
|
|
460
855
|
}
|
|
856
|
+
} else {
|
|
857
|
+
const errorText = await onairosSignupResponse.text();
|
|
858
|
+
console.warn('โ ๏ธ Could not create Enoch auth token for YouTube:', errorText);
|
|
461
859
|
}
|
|
462
860
|
} catch (tokenError) {
|
|
463
|
-
console.warn('โ ๏ธ Error creating auth token:', tokenError);
|
|
861
|
+
console.warn('โ ๏ธ Error creating Enoch auth token for YouTube:', tokenError);
|
|
862
|
+
// Continue without token - backend will handle gracefully
|
|
464
863
|
}
|
|
864
|
+
} else {
|
|
865
|
+
console.log('โ
Found existing authentication token for YouTube auth');
|
|
866
|
+
console.log('๐ Token preview:', `${authToken.substring(0, 20)}...`);
|
|
465
867
|
}
|
|
466
868
|
console.log('๐ Linking YouTube data to user:', finalUsername);
|
|
869
|
+
console.log('๐ Using auth token for linking:', authToken ? `${authToken.substring(0, 20)}...` : 'No token');
|
|
467
870
|
console.log('๐บ YouTube channel name:', channelName);
|
|
468
871
|
|
|
469
|
-
//
|
|
872
|
+
// โ
CRITICAL: Enhanced payload with comprehensive refresh token data
|
|
873
|
+
const backendPayload = {
|
|
874
|
+
session: {
|
|
875
|
+
username: finalUsername,
|
|
876
|
+
platform: 'youtube',
|
|
877
|
+
timestamp: new Date().toISOString(),
|
|
878
|
+
channelName: channelName,
|
|
879
|
+
channelId: channelId
|
|
880
|
+
},
|
|
881
|
+
googleUser: (_userInfo$data27 = userInfo.data) === null || _userInfo$data27 === void 0 ? void 0 : _userInfo$data27.user,
|
|
882
|
+
accessToken: tokens.accessToken,
|
|
883
|
+
idToken: tokens.idToken,
|
|
884
|
+
refreshToken: refreshToken,
|
|
885
|
+
// โ
CRITICAL: Include refresh token
|
|
886
|
+
serverAuthCode: refreshToken,
|
|
887
|
+
// โ
Alternative refresh mechanism (same as refreshToken)
|
|
888
|
+
|
|
889
|
+
// โ
CRITICAL: Additional compatibility fields for backend
|
|
890
|
+
refresh_token: refreshToken,
|
|
891
|
+
// Snake case version
|
|
892
|
+
server_auth_code: refreshToken,
|
|
893
|
+
// Snake case version
|
|
894
|
+
authCode: refreshToken,
|
|
895
|
+
// Alternative naming
|
|
896
|
+
|
|
897
|
+
// Include user account linking information
|
|
898
|
+
userAccountInfo: {
|
|
899
|
+
username: finalUsername,
|
|
900
|
+
email: (_userInfo$data28 = userInfo.data) === null || _userInfo$data28 === void 0 || (_userInfo$data28 = _userInfo$data28.user) === null || _userInfo$data28 === void 0 ? void 0 : _userInfo$data28.email,
|
|
901
|
+
authToken: authToken,
|
|
902
|
+
channelName: channelName,
|
|
903
|
+
channelId: channelId,
|
|
904
|
+
// CRITICAL: Include user identifier that matches your database
|
|
905
|
+
userIdentifier: authToken ? `user-${authToken.substring(0, 10)}` : `youtube-${(_userInfo$data29 = userInfo.data) === null || _userInfo$data29 === void 0 || (_userInfo$data29 = _userInfo$data29.user) === null || _userInfo$data29 === void 0 ? void 0 : _userInfo$data29.email}`,
|
|
906
|
+
googleId: (_userInfo$data30 = userInfo.data) === null || _userInfo$data30 === void 0 || (_userInfo$data30 = _userInfo$data30.user) === null || _userInfo$data30 === void 0 ? void 0 : _userInfo$data30.id,
|
|
907
|
+
appleUserId: (_authToken = authToken) !== null && _authToken !== void 0 && _authToken.includes('apple') ? authToken.split('.')[1] : null,
|
|
908
|
+
// โ
CRITICAL: Also include refresh token in userAccountInfo
|
|
909
|
+
refreshToken: refreshToken,
|
|
910
|
+
serverAuthCode: refreshToken
|
|
911
|
+
},
|
|
912
|
+
// Token expiry information
|
|
913
|
+
tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
|
|
914
|
+
// 1 hour from now
|
|
915
|
+
// Force refresh token request
|
|
916
|
+
requestRefreshToken: true,
|
|
917
|
+
// โ
CRITICAL: Debug information for backend
|
|
918
|
+
debugInfo: {
|
|
919
|
+
hasRefreshToken: !!refreshToken,
|
|
920
|
+
refreshTokenType: refreshToken ? refreshToken.startsWith('4/') ? 'serverAuthCode' : 'refreshToken' : 'none',
|
|
921
|
+
configuredForRefresh: true,
|
|
922
|
+
forcedConsent: true,
|
|
923
|
+
refreshTokenValue: refreshToken // Include actual value for debugging
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
console.log('๐ค BACKEND PAYLOAD SUMMARY:');
|
|
927
|
+
console.log('- hasAccessToken:', !!backendPayload.accessToken);
|
|
928
|
+
console.log('- hasRefreshToken:', !!backendPayload.refreshToken);
|
|
929
|
+
console.log('- hasServerAuthCode:', !!backendPayload.serverAuthCode);
|
|
930
|
+
console.log('- refreshTokenType:', backendPayload.debugInfo.refreshTokenType);
|
|
931
|
+
console.log('- userEmail:', (_userInfo$data31 = userInfo.data) === null || _userInfo$data31 === void 0 || (_userInfo$data31 = _userInfo$data31.user) === null || _userInfo$data31 === void 0 ? void 0 : _userInfo$data31.email);
|
|
932
|
+
console.log('- channelName:', channelName);
|
|
933
|
+
console.log('๐ COMPLETE BACKEND PAYLOAD:');
|
|
934
|
+
console.log(JSON.stringify(backendPayload, null, 2));
|
|
935
|
+
|
|
936
|
+
// Send the tokens to your backend for YouTube data processing with ENHANCED LOGGING
|
|
937
|
+
console.log('๐ค Sending YouTube auth to backend with refresh token:', !!refreshToken);
|
|
470
938
|
const backendResponse = await fetch('https://api2.onairos.uk/youtube/native-auth', {
|
|
471
939
|
method: 'POST',
|
|
472
940
|
headers: {
|
|
473
941
|
'Content-Type': 'application/json',
|
|
474
942
|
...(authToken && {
|
|
475
|
-
'Authorization':
|
|
476
|
-
})
|
|
943
|
+
'Authorization': authToken
|
|
944
|
+
}) // Include auth token if available
|
|
477
945
|
},
|
|
478
|
-
body: JSON.stringify(
|
|
479
|
-
session: {
|
|
480
|
-
username: finalUsername,
|
|
481
|
-
platform: 'youtube',
|
|
482
|
-
timestamp: new Date().toISOString(),
|
|
483
|
-
channelName: channelName,
|
|
484
|
-
channelId: channelId
|
|
485
|
-
},
|
|
486
|
-
googleUser: userInfo.user,
|
|
487
|
-
accessToken: tokens.accessToken,
|
|
488
|
-
idToken: tokens.idToken,
|
|
489
|
-
refreshToken: refreshToken,
|
|
490
|
-
// CRITICAL: Include refresh token
|
|
491
|
-
serverAuthCode: currentUser === null || currentUser === void 0 ? void 0 : currentUser.serverAuthCode,
|
|
492
|
-
userAccountInfo: {
|
|
493
|
-
username: finalUsername,
|
|
494
|
-
email: (_userInfo$user6 = userInfo.user) === null || _userInfo$user6 === void 0 ? void 0 : _userInfo$user6.email,
|
|
495
|
-
authToken: authToken,
|
|
496
|
-
channelName: channelName,
|
|
497
|
-
channelId: channelId,
|
|
498
|
-
userIdentifier: authToken ? `user-${authToken.substring(0, 10)}` : `youtube-${(_userInfo$user7 = userInfo.user) === null || _userInfo$user7 === void 0 ? void 0 : _userInfo$user7.email}`,
|
|
499
|
-
googleId: (_userInfo$user8 = userInfo.user) === null || _userInfo$user8 === void 0 ? void 0 : _userInfo$user8.id
|
|
500
|
-
},
|
|
501
|
-
tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
|
|
502
|
-
// 1 hour from now
|
|
503
|
-
requestRefreshToken: true
|
|
504
|
-
})
|
|
946
|
+
body: JSON.stringify(backendPayload)
|
|
505
947
|
});
|
|
948
|
+
console.log('๐ก Backend response status:', backendResponse.status);
|
|
949
|
+
console.log('๐ก Backend response headers:', backendResponse.headers);
|
|
506
950
|
if (backendResponse.ok) {
|
|
951
|
+
var _responseData$validat2, _responseData$tempora2;
|
|
507
952
|
const responseData = await backendResponse.json();
|
|
508
|
-
console.log('โ
YouTube connection
|
|
953
|
+
console.log('โ
YouTube connection successful');
|
|
954
|
+
console.log('๐ COMPLETE BACKEND RESPONSE:');
|
|
955
|
+
console.log(JSON.stringify(responseData, null, 2));
|
|
956
|
+
|
|
957
|
+
// โ
Enhanced verification with temporary mode detection (exact backend fields)
|
|
958
|
+
const isTemporaryMode = ((_responseData$validat2 = responseData.validation) === null || _responseData$validat2 === void 0 ? void 0 : _responseData$validat2.isTemporaryMode) === true || ((_responseData$tempora2 = responseData.temporaryMode) === null || _responseData$tempora2 === void 0 ? void 0 : _responseData$tempora2.enabled) === true || responseData.isTemporaryMode === true || responseData.message && responseData.message.includes('temporary access token mode');
|
|
959
|
+
if (isTemporaryMode) {
|
|
960
|
+
console.log('๐ [YOUTUBE AUTH] YouTube connected in temporary mode');
|
|
961
|
+
console.log('โ
[YOUTUBE AUTH] Training will work, but connection expires in ~1 hour');
|
|
962
|
+
console.log('โน๏ธ [YOUTUBE AUTH] User can reconnect later for refresh tokens if needed');
|
|
963
|
+
} else if (responseData.hasRefreshToken || responseData.refreshTokenReceived) {
|
|
964
|
+
console.log('โ
[YOUTUBE AUTH] Backend confirmed refresh token received');
|
|
965
|
+
console.log('โ
[YOUTUBE AUTH] Full YouTube connection with persistent access');
|
|
966
|
+
} else {
|
|
967
|
+
console.warn('โ ๏ธ [YOUTUBE AUTH] Backend did not confirm refresh token');
|
|
968
|
+
console.warn('๐ [YOUTUBE AUTH] Response data keys:', Object.keys(responseData));
|
|
969
|
+
console.warn('โ ๏ธ [YOUTUBE AUTH] Connection may fail when tokens expire');
|
|
970
|
+
}
|
|
509
971
|
return true;
|
|
510
972
|
} else {
|
|
511
973
|
const errorData = await backendResponse.text();
|
|
512
|
-
console.error('โ
|
|
974
|
+
console.error('โ YouTube auth failed:', backendResponse.status);
|
|
975
|
+
console.error('๐ BACKEND ERROR RESPONSE:');
|
|
976
|
+
console.error(errorData);
|
|
513
977
|
return false;
|
|
514
978
|
}
|
|
515
979
|
} catch (error) {
|
|
516
980
|
console.error('โ Google Sign-In error:', error);
|
|
517
|
-
|
|
518
|
-
statusCodes: StatusCodes
|
|
519
|
-
} = require('@react-native-google-signin/google-signin');
|
|
520
|
-
if (error.code === StatusCodes.SIGN_IN_CANCELLED) {
|
|
981
|
+
if (error.code === _googleSignin.statusCodes.SIGN_IN_CANCELLED) {
|
|
521
982
|
console.log('User cancelled Google Sign-In');
|
|
522
|
-
} else if (error.code ===
|
|
983
|
+
} else if (error.code === _googleSignin.statusCodes.IN_PROGRESS) {
|
|
523
984
|
console.log('Google Sign-In already in progress');
|
|
524
|
-
} else if (error.code ===
|
|
985
|
+
} else if (error.code === _googleSignin.statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
|
|
525
986
|
console.log('Google Play Services not available');
|
|
526
987
|
}
|
|
527
988
|
return false;
|
|
528
989
|
}
|
|
529
990
|
}
|
|
530
|
-
return false;
|
|
531
|
-
};
|
|
532
991
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Extract the authorization code
|
|
545
|
-
return parsedUrl.searchParams.get('code');
|
|
546
|
-
} catch (error) {
|
|
547
|
-
console.error('Error handling OAuth callback:', error);
|
|
548
|
-
return null;
|
|
992
|
+
// Instagram is commented out in the UI, but keeping the code for future use
|
|
993
|
+
if (platform === 'instagram') {
|
|
994
|
+
// Simulate Facebook Login SDK for Instagram
|
|
995
|
+
console.log('Initiating Facebook Login for Instagram');
|
|
996
|
+
return new Promise(resolve => {
|
|
997
|
+
setTimeout(() => {
|
|
998
|
+
console.log('Facebook Login completed successfully');
|
|
999
|
+
resolve(true);
|
|
1000
|
+
}, 1000);
|
|
1001
|
+
});
|
|
549
1002
|
}
|
|
1003
|
+
return false;
|
|
550
1004
|
};
|
|
551
1005
|
|
|
552
|
-
/**
|
|
553
|
-
*
|
|
554
|
-
* @param url The URL to check
|
|
555
|
-
* @returns True if the URL is an OAuth callback
|
|
1006
|
+
/**
|
|
1007
|
+
* Check if a URL is an OAuth callback
|
|
556
1008
|
*/
|
|
557
|
-
exports.
|
|
1009
|
+
exports.initiateNativeAuth = initiateNativeAuth;
|
|
558
1010
|
const isOAuthCallback = url => {
|
|
559
|
-
|
|
560
|
-
return url.startsWith('onairosanime://auth/');
|
|
1011
|
+
return url.includes('auth/callback') || url.includes('code=');
|
|
561
1012
|
};
|
|
562
1013
|
|
|
563
|
-
/**
|
|
564
|
-
*
|
|
1014
|
+
/**
|
|
1015
|
+
* Exchange authorization code for access token
|
|
1016
|
+
* This would typically be done on a server, but we're simulating it here
|
|
565
1017
|
*/
|
|
566
1018
|
exports.isOAuthCallback = isOAuthCallback;
|
|
567
|
-
const
|
|
1019
|
+
const exchangeCodeForToken = async (code, platform) => {
|
|
1020
|
+
console.log(`Exchanging code for token for platform: ${platform}`);
|
|
568
1021
|
try {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
// Test multiple endpoints for better reliability
|
|
572
|
-
const testEndpoints = ['https://api2.onairos.uk/health', 'https://api2.onairos.uk' // Base URL
|
|
573
|
-
];
|
|
574
|
-
let lastError = null;
|
|
575
|
-
for (const endpoint of testEndpoints) {
|
|
576
|
-
try {
|
|
577
|
-
console.log(`๐ Testing endpoint: ${endpoint}`);
|
|
578
|
-
const controller = new AbortController();
|
|
579
|
-
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
|
|
580
|
-
|
|
581
|
-
const response = await fetch(endpoint, {
|
|
582
|
-
method: 'GET',
|
|
583
|
-
headers: {
|
|
584
|
-
'Content-Type': 'application/json',
|
|
585
|
-
'User-Agent': 'OnairosReactNative/1.0'
|
|
586
|
-
},
|
|
587
|
-
signal: controller.signal
|
|
588
|
-
});
|
|
589
|
-
clearTimeout(timeoutId);
|
|
590
|
-
console.log(`๐ API connectivity test response for ${endpoint}:`, response.status);
|
|
591
|
-
if (response.ok || response.status === 404) {
|
|
592
|
-
// Accept 404 as it means the server is reachable
|
|
593
|
-
console.log('โ
API server is reachable');
|
|
594
|
-
return {
|
|
595
|
-
success: true
|
|
596
|
-
};
|
|
597
|
-
} else {
|
|
598
|
-
console.log(`โ ๏ธ API server responded with status ${response.status} for ${endpoint}`);
|
|
599
|
-
lastError = `API server error: ${response.status}`;
|
|
600
|
-
// Continue to next endpoint
|
|
601
|
-
}
|
|
602
|
-
} catch (fetchError) {
|
|
603
|
-
console.log(`โ Failed to reach ${endpoint}:`, fetchError);
|
|
604
|
-
if (fetchError.name === 'AbortError') {
|
|
605
|
-
lastError = 'Connection timeout - API server took too long to respond';
|
|
606
|
-
} else if (fetchError.message.includes('Network request failed')) {
|
|
607
|
-
lastError = 'Network error - check your internet connection';
|
|
608
|
-
} else if (fetchError.message.includes('not connected to the internet')) {
|
|
609
|
-
lastError = 'No internet connection';
|
|
610
|
-
} else {
|
|
611
|
-
lastError = `Network error: ${fetchError.message}`;
|
|
612
|
-
}
|
|
1022
|
+
// Use the proxy server to exchange the code for a token
|
|
1023
|
+
const tokenUrl = `https://api2.onairos.uk/${platform}/token`;
|
|
613
1024
|
|
|
614
|
-
|
|
615
|
-
|
|
1025
|
+
// Make a POST request to the proxy
|
|
1026
|
+
const response = await fetch(tokenUrl, {
|
|
1027
|
+
method: 'POST',
|
|
1028
|
+
headers: {
|
|
1029
|
+
'Content-Type': 'application/json'
|
|
1030
|
+
},
|
|
1031
|
+
body: JSON.stringify({
|
|
1032
|
+
code: code,
|
|
1033
|
+
platform: platform
|
|
1034
|
+
})
|
|
1035
|
+
});
|
|
1036
|
+
if (!response.ok) {
|
|
1037
|
+
console.error(`Error exchanging code for token: ${response.status}`);
|
|
1038
|
+
throw new Error(`Token exchange failed with status ${response.status}`);
|
|
616
1039
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
error: lastError || 'Cannot reach API server'
|
|
621
|
-
};
|
|
1040
|
+
const data = await response.json();
|
|
1041
|
+
console.log(`Token exchange successful for ${platform}`);
|
|
1042
|
+
return data;
|
|
622
1043
|
} catch (error) {
|
|
623
|
-
console.error(
|
|
624
|
-
return {
|
|
625
|
-
success: false,
|
|
626
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
};
|
|
1044
|
+
console.error(`Error exchanging code for token:`, error);
|
|
630
1045
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
*/
|
|
634
|
-
exports.testApiConnectivity = testApiConnectivity;
|
|
635
|
-
const refreshGoogleTokens = async () => {
|
|
636
|
-
try {
|
|
637
|
-
console.log('๐ Attempting to refresh Google tokens...');
|
|
638
|
-
const {
|
|
639
|
-
GoogleSignin
|
|
640
|
-
} = require('@react-native-google-signin/google-signin');
|
|
641
|
-
const currentUser = await GoogleSignin.getCurrentUser();
|
|
642
|
-
if (!currentUser) {
|
|
643
|
-
console.log('โ User not signed in to Google, cannot refresh tokens');
|
|
644
|
-
return null;
|
|
645
|
-
}
|
|
646
|
-
const tokens = await GoogleSignin.getTokens();
|
|
647
|
-
console.log('โ
Successfully refreshed Google tokens');
|
|
1046
|
+
// Fallback to simulation if the API call fails
|
|
1047
|
+
console.log('Falling back to simulated token response');
|
|
648
1048
|
return {
|
|
649
|
-
|
|
650
|
-
|
|
1049
|
+
access_token: `${platform}_access_token_${Math.random().toString(36).substring(7)}`,
|
|
1050
|
+
refresh_token: `${platform}_refresh_token_${Math.random().toString(36).substring(7)}`,
|
|
1051
|
+
expires_in: 3600
|
|
651
1052
|
};
|
|
652
|
-
} catch (error) {
|
|
653
|
-
console.error('โ Failed to refresh Google tokens:', error);
|
|
654
|
-
|
|
655
|
-
// If refresh fails, try to sign in again
|
|
656
|
-
try {
|
|
657
|
-
console.log('๐ Refresh failed, attempting re-authentication...');
|
|
658
|
-
const {
|
|
659
|
-
GoogleSignin
|
|
660
|
-
} = require('@react-native-google-signin/google-signin');
|
|
661
|
-
const userInfo = await GoogleSignin.signIn();
|
|
662
|
-
const tokens = await GoogleSignin.getTokens();
|
|
663
|
-
console.log('โ
Re-authentication successful');
|
|
664
|
-
return {
|
|
665
|
-
accessToken: tokens.accessToken,
|
|
666
|
-
idToken: tokens.idToken
|
|
667
|
-
};
|
|
668
|
-
} catch (signInError) {
|
|
669
|
-
console.error('โ Re-authentication also failed:', signInError);
|
|
670
|
-
return null;
|
|
671
|
-
}
|
|
672
1053
|
}
|
|
673
1054
|
};
|
|
674
1055
|
|
|
675
|
-
/**
|
|
676
|
-
*
|
|
1056
|
+
/**
|
|
1057
|
+
* Refresh YouTube tokens when they expire
|
|
1058
|
+
* This should be called when the backend reports token expiry
|
|
677
1059
|
*/
|
|
678
|
-
exports.
|
|
1060
|
+
exports.exchangeCodeForToken = exchangeCodeForToken;
|
|
679
1061
|
const refreshYouTubeTokens = async () => {
|
|
680
1062
|
try {
|
|
681
|
-
var _currentUser$
|
|
1063
|
+
var _currentUser$user3;
|
|
682
1064
|
console.log('๐ Refreshing YouTube tokens...');
|
|
683
1065
|
|
|
684
1066
|
// Get fresh tokens from Google SDK
|
|
685
|
-
const freshTokens = await
|
|
1067
|
+
const freshTokens = await _googleSignin.GoogleSignin.getTokens();
|
|
686
1068
|
if (!freshTokens) {
|
|
687
1069
|
console.error('โ Failed to get fresh tokens from Google SDK');
|
|
688
1070
|
return false;
|
|
689
1071
|
}
|
|
690
1072
|
|
|
691
1073
|
// Get current user info
|
|
692
|
-
const
|
|
693
|
-
GoogleSignin
|
|
694
|
-
} = require('@react-native-google-signin/google-signin');
|
|
695
|
-
const currentUser = await GoogleSignin.getCurrentUser();
|
|
1074
|
+
const currentUser = await _googleSignin.GoogleSignin.getCurrentUser();
|
|
696
1075
|
if (!currentUser) {
|
|
697
1076
|
console.error('โ No current Google user found');
|
|
698
1077
|
return false;
|
|
@@ -710,14 +1089,15 @@ const refreshYouTubeTokens = async () => {
|
|
|
710
1089
|
method: 'POST',
|
|
711
1090
|
headers: {
|
|
712
1091
|
'Content-Type': 'application/json',
|
|
713
|
-
'Authorization':
|
|
1092
|
+
'Authorization': authToken
|
|
714
1093
|
},
|
|
715
1094
|
body: JSON.stringify({
|
|
716
1095
|
accessToken: freshTokens.accessToken,
|
|
717
1096
|
idToken: freshTokens.idToken,
|
|
718
1097
|
refreshToken: currentUser.serverAuthCode,
|
|
719
|
-
userEmail: (_currentUser$
|
|
1098
|
+
userEmail: (_currentUser$user3 = currentUser.user) === null || _currentUser$user3 === void 0 ? void 0 : _currentUser$user3.email,
|
|
720
1099
|
tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
|
|
1100
|
+
// 1 hour from now
|
|
721
1101
|
timestamp: new Date().toISOString()
|
|
722
1102
|
})
|
|
723
1103
|
});
|
|
@@ -736,332 +1116,186 @@ const refreshYouTubeTokens = async () => {
|
|
|
736
1116
|
}
|
|
737
1117
|
};
|
|
738
1118
|
|
|
739
|
-
/**
|
|
740
|
-
*
|
|
1119
|
+
/**
|
|
1120
|
+
* Trigger training restart after YouTube re-authentication
|
|
1121
|
+
* This signals the backend to restart training with the new refresh token
|
|
741
1122
|
*/
|
|
742
1123
|
exports.refreshYouTubeTokens = refreshYouTubeTokens;
|
|
743
|
-
const
|
|
1124
|
+
const triggerTrainingRestart = async (username, authToken) => {
|
|
744
1125
|
try {
|
|
745
|
-
console.log('
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
if (
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
};
|
|
1126
|
+
console.log('๐ [TRAINING RESTART] Triggering training restart for user:', username);
|
|
1127
|
+
const response = await fetch('https://api2.onairos.uk/mobile-training/restart', {
|
|
1128
|
+
method: 'POST',
|
|
1129
|
+
headers: {
|
|
1130
|
+
'Content-Type': 'application/json',
|
|
1131
|
+
'Authorization': authToken
|
|
1132
|
+
},
|
|
1133
|
+
body: JSON.stringify({
|
|
1134
|
+
username: username,
|
|
1135
|
+
reason: 'youtube_reauth',
|
|
1136
|
+
platform: 'youtube',
|
|
1137
|
+
timestamp: new Date().toISOString(),
|
|
1138
|
+
requestNewTraining: true
|
|
1139
|
+
})
|
|
1140
|
+
});
|
|
1141
|
+
if (response.ok) {
|
|
1142
|
+
const responseData = await response.json();
|
|
1143
|
+
console.log('โ
[TRAINING RESTART] Training restart successful:', responseData);
|
|
1144
|
+
} else {
|
|
1145
|
+
const errorData = await response.text();
|
|
1146
|
+
console.error('โ [TRAINING RESTART] Training restart failed:', response.status, errorData);
|
|
1147
|
+
throw new Error(`Training restart failed: ${response.status}`);
|
|
767
1148
|
}
|
|
768
|
-
console.warn('โ ๏ธ OAuth callback missing platform or code');
|
|
769
|
-
return {
|
|
770
|
-
success: false
|
|
771
|
-
};
|
|
772
1149
|
} catch (error) {
|
|
773
|
-
console.error('โ Error
|
|
774
|
-
|
|
775
|
-
success: false
|
|
776
|
-
};
|
|
1150
|
+
console.error('โ [TRAINING RESTART] Error triggering training restart:', error);
|
|
1151
|
+
throw error;
|
|
777
1152
|
}
|
|
778
1153
|
};
|
|
779
1154
|
|
|
780
|
-
/**
|
|
781
|
-
*
|
|
782
|
-
*
|
|
1155
|
+
/**
|
|
1156
|
+
* Test function to verify YouTube refresh token functionality
|
|
1157
|
+
* Call this in your app to test the YouTube connection
|
|
783
1158
|
*/
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
console.log('
|
|
787
|
-
|
|
788
|
-
//
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
1159
|
+
const testYouTubeRefreshToken = async username => {
|
|
1160
|
+
console.log('๐งช Testing YouTube refresh token functionality...');
|
|
1161
|
+
console.log('๐ค User:', username);
|
|
1162
|
+
try {
|
|
1163
|
+
// Test the debug function first
|
|
1164
|
+
const debugInfo = await debugYouTubeTokens();
|
|
1165
|
+
console.log('๐ Current token status:', debugInfo);
|
|
1166
|
+
if (!debugInfo.hasRefreshToken) {
|
|
1167
|
+
console.log('โ ๏ธ No refresh token found - attempting to fix...');
|
|
1168
|
+
const success = await fixUserYouTubeConnection(username);
|
|
1169
|
+
if (success) {
|
|
1170
|
+
console.log('โ
YouTube connection fixed! Testing again...');
|
|
1171
|
+
const newDebugInfo = await debugYouTubeTokens();
|
|
1172
|
+
console.log('๐ New token status:', newDebugInfo);
|
|
1173
|
+
} else {
|
|
1174
|
+
console.error('โ Failed to fix YouTube connection');
|
|
1175
|
+
}
|
|
1176
|
+
} else {
|
|
1177
|
+
console.log('โ
Refresh token already available');
|
|
1178
|
+
}
|
|
1179
|
+
} catch (error) {
|
|
1180
|
+
console.error('โ Error testing YouTube refresh token:', error);
|
|
797
1181
|
}
|
|
798
1182
|
};
|
|
799
1183
|
|
|
800
|
-
/**
|
|
801
|
-
* Request email verification
|
|
802
|
-
* @param email Email address to verify
|
|
803
|
-
* @param testMode Whether to use test mode
|
|
804
|
-
* @returns Promise with verification result
|
|
1184
|
+
/**
|
|
1185
|
+
* Request email verification code
|
|
805
1186
|
*/
|
|
806
|
-
exports.
|
|
1187
|
+
exports.testYouTubeRefreshToken = testYouTubeRefreshToken;
|
|
807
1188
|
const requestEmailVerification = async (email, testMode = false) => {
|
|
808
1189
|
try {
|
|
809
1190
|
console.log('๐ง Requesting email verification for:', email);
|
|
810
|
-
const response = await (
|
|
1191
|
+
const response = await fetch(`${_api.API_CONFIG.BASE_URL}/email/verification`, {
|
|
811
1192
|
method: 'POST',
|
|
1193
|
+
headers: (0, _api.getApiHeaders)(),
|
|
812
1194
|
body: JSON.stringify({
|
|
813
1195
|
email,
|
|
814
1196
|
action: 'request',
|
|
815
1197
|
testMode
|
|
816
1198
|
})
|
|
817
1199
|
});
|
|
818
|
-
const
|
|
819
|
-
if (response.ok
|
|
820
|
-
console.log('โ
Email verification requested successfully');
|
|
1200
|
+
const result = await response.json();
|
|
1201
|
+
if (response.ok) {
|
|
821
1202
|
return {
|
|
822
1203
|
success: true,
|
|
823
|
-
message:
|
|
1204
|
+
message: result.message || 'Verification code sent to your email'
|
|
824
1205
|
};
|
|
825
1206
|
} else {
|
|
826
|
-
console.error('โ Email verification request failed:', data.error);
|
|
827
1207
|
return {
|
|
828
1208
|
success: false,
|
|
829
|
-
error:
|
|
1209
|
+
error: result.message || 'Failed to send verification code'
|
|
830
1210
|
};
|
|
831
1211
|
}
|
|
832
1212
|
} catch (error) {
|
|
833
1213
|
console.error('โ Error requesting email verification:', error);
|
|
834
1214
|
return {
|
|
835
1215
|
success: false,
|
|
836
|
-
error: error
|
|
1216
|
+
error: 'Network error. Please check your connection and try again.'
|
|
837
1217
|
};
|
|
838
1218
|
}
|
|
839
1219
|
};
|
|
840
1220
|
|
|
841
|
-
/**
|
|
842
|
-
* Verify email code
|
|
843
|
-
* @param email Email address
|
|
844
|
-
* @param code Verification code
|
|
845
|
-
* @param testMode Whether to use test mode
|
|
846
|
-
* @returns Promise with verification result and JWT token
|
|
1221
|
+
/**
|
|
1222
|
+
* Verify email code
|
|
847
1223
|
*/
|
|
848
1224
|
exports.requestEmailVerification = requestEmailVerification;
|
|
849
1225
|
const verifyEmailCode = async (email, code, testMode = false) => {
|
|
850
1226
|
try {
|
|
851
1227
|
console.log('๐ Verifying email code for:', email);
|
|
852
|
-
const response = await (
|
|
1228
|
+
const response = await fetch(`${_api.API_CONFIG.BASE_URL}/email/verification`, {
|
|
853
1229
|
method: 'POST',
|
|
1230
|
+
headers: (0, _api.getApiHeaders)(),
|
|
854
1231
|
body: JSON.stringify({
|
|
855
1232
|
email,
|
|
856
|
-
action: 'verify',
|
|
857
1233
|
code,
|
|
1234
|
+
action: 'verify',
|
|
858
1235
|
testMode
|
|
859
1236
|
})
|
|
860
1237
|
});
|
|
861
|
-
const
|
|
862
|
-
if (response.ok
|
|
863
|
-
console.log('โ
Email verification successful');
|
|
864
|
-
|
|
865
|
-
// Store JWT token if received
|
|
866
|
-
if (data.token || data.jwtToken) {
|
|
867
|
-
const jwtToken = data.token || data.jwtToken;
|
|
868
|
-
await (0, _apiKeyService.storeJWT)(jwtToken);
|
|
869
|
-
console.log('๐ซ JWT token stored successfully');
|
|
870
|
-
}
|
|
1238
|
+
const result = await response.json();
|
|
1239
|
+
if (response.ok) {
|
|
871
1240
|
return {
|
|
872
1241
|
success: true,
|
|
873
|
-
message:
|
|
874
|
-
existingUser:
|
|
875
|
-
token:
|
|
1242
|
+
message: result.message || 'Email verified successfully',
|
|
1243
|
+
existingUser: result.existingUser || false,
|
|
1244
|
+
token: result.token
|
|
876
1245
|
};
|
|
877
1246
|
} else {
|
|
878
|
-
console.error('โ Email verification failed:', data.error);
|
|
879
1247
|
return {
|
|
880
1248
|
success: false,
|
|
881
|
-
error:
|
|
1249
|
+
error: result.message || 'Invalid verification code'
|
|
882
1250
|
};
|
|
883
1251
|
}
|
|
884
1252
|
} catch (error) {
|
|
885
1253
|
console.error('โ Error verifying email code:', error);
|
|
886
1254
|
return {
|
|
887
1255
|
success: false,
|
|
888
|
-
error: error
|
|
1256
|
+
error: 'Network error. Please check your connection and try again.'
|
|
889
1257
|
};
|
|
890
1258
|
}
|
|
891
1259
|
};
|
|
892
1260
|
|
|
893
|
-
/**
|
|
894
|
-
* Check email verification status
|
|
895
|
-
* @param email Email address
|
|
896
|
-
* @param testMode Whether to use test mode
|
|
897
|
-
* @returns Promise with status result
|
|
1261
|
+
/**
|
|
1262
|
+
* Check email verification status
|
|
898
1263
|
*/
|
|
899
1264
|
exports.verifyEmailCode = verifyEmailCode;
|
|
900
1265
|
const checkEmailVerificationStatus = async (email, testMode = false) => {
|
|
901
1266
|
try {
|
|
902
|
-
|
|
903
|
-
const response = await (0, _apiKeyService.makeDeveloperRequest)('/email/verification/status', {
|
|
1267
|
+
const response = await fetch(`${_api.API_CONFIG.BASE_URL}/email/verification/status`, {
|
|
904
1268
|
method: 'POST',
|
|
1269
|
+
headers: (0, _api.getApiHeaders)(),
|
|
905
1270
|
body: JSON.stringify({
|
|
906
1271
|
email,
|
|
907
1272
|
testMode
|
|
908
1273
|
})
|
|
909
1274
|
});
|
|
910
|
-
const
|
|
911
|
-
if (response.ok && data.success) {
|
|
912
|
-
return {
|
|
913
|
-
success: true,
|
|
914
|
-
isPending: data.isPending || false
|
|
915
|
-
};
|
|
916
|
-
} else {
|
|
917
|
-
return {
|
|
918
|
-
success: false,
|
|
919
|
-
error: data.error || 'Failed to check verification status'
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
} catch (error) {
|
|
923
|
-
console.error('โ Error checking email verification status:', error);
|
|
1275
|
+
const result = await response.json();
|
|
924
1276
|
return {
|
|
925
|
-
success:
|
|
926
|
-
|
|
1277
|
+
success: response.ok,
|
|
1278
|
+
isPending: result.isPending || false,
|
|
1279
|
+
message: result.message
|
|
927
1280
|
};
|
|
928
|
-
}
|
|
929
|
-
};
|
|
930
|
-
|
|
931
|
-
/**
|
|
932
|
-
* Disconnect a platform (uses developer API key)
|
|
933
|
-
* @param platform Platform to disconnect
|
|
934
|
-
* @param username Username associated with the platform
|
|
935
|
-
* @returns Promise with disconnect result
|
|
936
|
-
*/
|
|
937
|
-
exports.checkEmailVerificationStatus = checkEmailVerificationStatus;
|
|
938
|
-
const disconnectPlatform = async (platform, username) => {
|
|
939
|
-
try {
|
|
940
|
-
console.log('๐ Disconnecting platform:', platform, 'for user:', username);
|
|
941
|
-
|
|
942
|
-
// Make authenticated API call to disconnect platform
|
|
943
|
-
const response = await (0, _apiKeyService.makeDeveloperRequest)('/revoke', {
|
|
944
|
-
method: 'POST',
|
|
945
|
-
body: JSON.stringify({
|
|
946
|
-
platform,
|
|
947
|
-
username
|
|
948
|
-
})
|
|
949
|
-
});
|
|
950
|
-
const data = await response.json();
|
|
951
|
-
if (response.ok && data.success) {
|
|
952
|
-
console.log(`โ
${platform} disconnected successfully`);
|
|
953
|
-
return {
|
|
954
|
-
success: true
|
|
955
|
-
};
|
|
956
|
-
} else {
|
|
957
|
-
console.error(`โ Failed to disconnect ${platform}:`, data.error);
|
|
958
|
-
return {
|
|
959
|
-
success: false,
|
|
960
|
-
error: data.error || 'Failed to disconnect platform'
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
} catch (error) {
|
|
964
|
-
console.error(`โ Error disconnecting ${platform}:`, error);
|
|
965
|
-
return {
|
|
966
|
-
success: false,
|
|
967
|
-
error: error instanceof Error ? error.message : 'Network error'
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
|
|
972
|
-
/**
|
|
973
|
-
* Store PIN for user (uses JWT authentication and extracts username from JWT)
|
|
974
|
-
* @param pin User PIN
|
|
975
|
-
* @param username Optional username (if not provided, extracts from JWT)
|
|
976
|
-
* @returns Promise with result
|
|
977
|
-
*/
|
|
978
|
-
exports.disconnectPlatform = disconnectPlatform;
|
|
979
|
-
const storePIN = async (pin, username) => {
|
|
980
|
-
try {
|
|
981
|
-
// Extract username from JWT if not provided
|
|
982
|
-
const userToStore = username || (0, _apiKeyService.extractUsernameFromJWT)();
|
|
983
|
-
if (!userToStore) {
|
|
984
|
-
console.error('โ No username available - either provide username or ensure JWT token is valid');
|
|
985
|
-
return {
|
|
986
|
-
success: false,
|
|
987
|
-
error: 'No username available for PIN storage'
|
|
988
|
-
};
|
|
989
|
-
}
|
|
990
|
-
console.log('๐ Storing PIN for user:', userToStore);
|
|
991
|
-
|
|
992
|
-
// Make authenticated request to store PIN (using developer API key for now)
|
|
993
|
-
const response = await (0, _apiKeyService.makeDeveloperRequest)('/store-pin/web', {
|
|
994
|
-
method: 'POST',
|
|
995
|
-
headers: {
|
|
996
|
-
'Content-Type': 'application/json'
|
|
997
|
-
},
|
|
998
|
-
body: JSON.stringify({
|
|
999
|
-
username: userToStore,
|
|
1000
|
-
pin
|
|
1001
|
-
})
|
|
1002
|
-
});
|
|
1003
|
-
const data = await response.json();
|
|
1004
|
-
if (response.ok && data.success) {
|
|
1005
|
-
console.log('โ
PIN stored successfully for user:', userToStore);
|
|
1006
|
-
return {
|
|
1007
|
-
success: true
|
|
1008
|
-
};
|
|
1009
|
-
} else {
|
|
1010
|
-
console.error('โ Failed to store PIN:', data.error);
|
|
1011
|
-
return {
|
|
1012
|
-
success: false,
|
|
1013
|
-
error: data.error || 'Failed to store PIN'
|
|
1014
|
-
};
|
|
1015
|
-
}
|
|
1016
1281
|
} catch (error) {
|
|
1017
|
-
console.error('โ Error
|
|
1282
|
+
console.error('โ Error checking email verification status:', error);
|
|
1018
1283
|
return {
|
|
1019
1284
|
success: false,
|
|
1020
|
-
|
|
1285
|
+
isPending: false,
|
|
1286
|
+
error: 'Network error'
|
|
1021
1287
|
};
|
|
1022
1288
|
}
|
|
1023
1289
|
};
|
|
1024
1290
|
|
|
1025
|
-
/**
|
|
1026
|
-
*
|
|
1027
|
-
* Helper function to retrieve stored JWT token from email verification or other sources
|
|
1291
|
+
/**
|
|
1292
|
+
* Initialize platform auth service
|
|
1028
1293
|
*/
|
|
1029
|
-
exports.
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
// Try different storage keys in order of preference
|
|
1035
|
-
const tokenSources = ['email_verification_token', 'onairos_jwt_token', 'enoch_token', 'auth_token'];
|
|
1036
|
-
for (const source of tokenSources) {
|
|
1037
|
-
const token = await _asyncStorage.default.getItem(source);
|
|
1038
|
-
if (token && token.length > 20) {
|
|
1039
|
-
console.log(`โ
JWT token found in ${source}:`, token.substring(0, 20) + '...');
|
|
1040
|
-
return token;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
console.warn('โ ๏ธ No JWT token found in storage');
|
|
1044
|
-
return null;
|
|
1045
|
-
} catch (error) {
|
|
1046
|
-
console.error('โ Error retrieving JWT token:', error);
|
|
1047
|
-
return null;
|
|
1048
|
-
}
|
|
1049
|
-
};
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* ๐ซ CLEAR STORED TOKENS
|
|
1053
|
-
* Helper function to clear all stored tokens (useful for logout)
|
|
1054
|
-
*/
|
|
1055
|
-
exports.getStoredJwtToken = getStoredJwtToken;
|
|
1056
|
-
const clearStoredTokens = async () => {
|
|
1057
|
-
try {
|
|
1058
|
-
console.log('๐งน Clearing all stored tokens...');
|
|
1059
|
-
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'];
|
|
1060
|
-
await Promise.all(tokenKeys.map(key => _asyncStorage.default.removeItem(key)));
|
|
1061
|
-
console.log('โ
All tokens cleared successfully');
|
|
1062
|
-
} catch (error) {
|
|
1063
|
-
console.error('โ Error clearing tokens:', error);
|
|
1064
|
-
}
|
|
1294
|
+
exports.checkEmailVerificationStatus = checkEmailVerificationStatus;
|
|
1295
|
+
const initializePlatformAuthService = () => {
|
|
1296
|
+
console.log('๐ง Platform auth service initialized');
|
|
1297
|
+
// Initialize Google Sign-In
|
|
1298
|
+
initializeGoogleSignIn();
|
|
1065
1299
|
};
|
|
1066
|
-
exports.
|
|
1300
|
+
exports.initializePlatformAuthService = initializePlatformAuthService;
|
|
1067
1301
|
//# sourceMappingURL=platformAuthService.js.map
|