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