@onairos/react-native 3.6.4 → 3.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/api/index.js +1 -1
- package/lib/commonjs/components/BodyText.js +1 -1
- package/lib/commonjs/components/BrandMark.js +1 -1
- package/lib/commonjs/components/CodeInput.js +1 -1
- package/lib/commonjs/components/EmailInput.js +1 -1
- package/lib/commonjs/components/GoogleButton.js +1 -1
- package/lib/commonjs/components/HeadingGroup.js +1 -1
- package/lib/commonjs/components/LLMDataInputModal.js +1 -1
- package/lib/commonjs/components/ModalHeader.js +1 -1
- package/lib/commonjs/components/ModalSheet.js +1 -1
- package/lib/commonjs/components/Onairos.js +1 -1
- package/lib/commonjs/components/OnairosButton.js +1 -1
- package/lib/commonjs/components/OnairosSignInButton.js +1 -1
- package/lib/commonjs/components/Overlay.js +1 -1
- package/lib/commonjs/components/PersonaImage.js +1 -1
- package/lib/commonjs/components/PersonaLoadingScreen.js +1 -1
- package/lib/commonjs/components/PersonalizationConsentScreen.js +1 -1
- package/lib/commonjs/components/PinCreationScreen.js +1 -1
- package/lib/commonjs/components/PinInput.js +1 -1
- package/lib/commonjs/components/PlatformConnectorsStep.js +1 -1
- package/lib/commonjs/components/PlatformList.js +1 -1
- package/lib/commonjs/components/PlatformToggle.js +1 -1
- package/lib/commonjs/components/PrimaryButton.js +1 -1
- package/lib/commonjs/components/SignInMatchAnimation.js +1 -1
- package/lib/commonjs/components/SignInStep.js +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +1 -1
- package/lib/commonjs/components/VerificationStep.js +1 -1
- package/lib/commonjs/components/WelcomeScreen.js +1 -1
- package/lib/commonjs/components/icons/Basicproficon.js +1 -1
- package/lib/commonjs/components/icons/Basicprofile.js +1 -1
- package/lib/commonjs/components/icons/Checkbox.js +1 -1
- package/lib/commonjs/components/icons/Checkmark.js +1 -1
- package/lib/commonjs/components/icons/Contentanalysis.js +1 -1
- package/lib/commonjs/components/icons/Contenticon.js +1 -1
- package/lib/commonjs/components/icons/EnochE.js +1 -1
- package/lib/commonjs/components/icons/Personalityicon.js +1 -1
- package/lib/commonjs/components/icons/Personalityprofile.js +1 -1
- package/lib/commonjs/components/icons/Personalitytraits.js +1 -1
- package/lib/commonjs/components/icons/Userpreferences.js +1 -1
- package/lib/commonjs/components/icons/index.js +1 -1
- package/lib/commonjs/components/onboarding/OAuthWebView.js +1 -1
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +1 -1
- package/lib/commonjs/components/onboarding/PinInput.js +1 -1
- package/lib/commonjs/components/onboarding/PlatformConnector.js +1 -1
- package/lib/commonjs/config/api.js +1 -1
- package/lib/commonjs/constants/index.js +1 -1
- package/lib/commonjs/context/AuthContext.js +1 -1
- package/lib/commonjs/hooks/useConnectedAccounts.js +1 -1
- package/lib/commonjs/hooks/useConnections.js +1 -1
- package/lib/commonjs/hooks/useCredentials.js +1 -1
- package/lib/commonjs/hooks/useUserConnections.js +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/services/apiClient.js +1 -1
- package/lib/commonjs/services/apiKeyService.js +924 -9
- package/lib/commonjs/services/authService.js +627 -10
- package/lib/commonjs/services/biometricPinService.js +1 -1
- package/lib/commonjs/services/chatGPTConversationExtractor.js +1 -1
- package/lib/commonjs/services/chatGPTConversationService.js +1 -1
- package/lib/commonjs/services/claudeConversationExtractor.js +1 -1
- package/lib/commonjs/services/claudeConversationService.js +1 -1
- package/lib/commonjs/services/connectedAccountsService.js +1 -1
- package/lib/commonjs/services/googleAuthService.js +1 -1
- package/lib/commonjs/services/hingeDataExtractor.js +1 -1
- package/lib/commonjs/services/hingeDataService.js +1 -1
- package/lib/commonjs/services/imageCompressionService.js +1 -1
- package/lib/commonjs/services/instagramDataExtractor.js +1 -1
- package/lib/commonjs/services/instagramDataService.js +1 -1
- package/lib/commonjs/services/jwtStorageService.js +1 -1
- package/lib/commonjs/services/linkedinDOMExtractor.js +1 -1
- package/lib/commonjs/services/linkedinProfileService.js +1 -1
- package/lib/commonjs/services/linkedinScrapingService.js +1 -1
- package/lib/commonjs/services/llmDataStorage.js +1 -1
- package/lib/commonjs/services/mobileTrainingService.js +1 -1
- package/lib/commonjs/services/oauthService.js +391 -11
- package/lib/commonjs/services/pinEncryptionService.js +1 -1
- package/lib/commonjs/services/pinStorageUtils.js +1 -1
- package/lib/commonjs/services/platformAuthService.js +1 -1
- package/lib/commonjs/services/sephoraDataExtractor.js +1 -1
- package/lib/commonjs/services/sephoraDataService.js +1 -1
- package/lib/commonjs/services/storageService.js +1 -1
- package/lib/commonjs/services/telegramDataExtractor.js +1 -1
- package/lib/commonjs/services/telegramDataService.js +1 -1
- package/lib/commonjs/services/trainingApiHelpers.js +1 -1
- package/lib/commonjs/services/userConnectionsService.js +1 -1
- package/lib/commonjs/services/youtubeMigrationService.js +1 -1
- package/lib/commonjs/theme/index.js +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types.js +1 -1
- package/lib/commonjs/utils/Portal.js +1 -1
- package/lib/commonjs/utils/api.js +1 -1
- package/lib/commonjs/utils/assetRegistry.js +1 -1
- package/lib/commonjs/utils/auth.js +1 -1
- package/lib/commonjs/utils/connectorTests.js +1 -1
- package/lib/commonjs/utils/crypto.js +1 -1
- package/lib/commonjs/utils/debugHelper.js +1 -1
- package/lib/commonjs/utils/encryption.js +1 -1
- package/lib/commonjs/utils/eventUtils.js +1 -1
- package/lib/commonjs/utils/haptics.js +1 -1
- package/lib/commonjs/utils/imagePreloader.js +1 -1
- package/lib/commonjs/utils/networkDiagnostics.js +1 -1
- package/lib/commonjs/utils/onairosApi.js +1 -1
- package/lib/commonjs/utils/programmaticFlow.js +1 -1
- package/lib/commonjs/utils/retryHelper.js +1 -1
- package/lib/commonjs/utils/secureStorage.js +1 -1
- package/lib/commonjs/utils/webviewScripts/chatgpt.js +1 -1
- package/lib/commonjs/utils/webviewScripts/claude.js +1 -1
- package/lib/commonjs/utils/webviewScripts/hinge.js +1 -1
- package/lib/commonjs/utils/webviewScripts/index.js +1 -1
- package/lib/commonjs/utils/webviewScripts/instagram.js +1 -1
- package/lib/commonjs/utils/webviewScripts/linkedin.js +1 -1
- package/lib/commonjs/utils/webviewScripts/sephora.js +1 -1
- package/lib/commonjs/utils/webviewScripts/telegram.js +1 -1
- package/lib/module/api/index.js +1 -1
- package/lib/module/components/BodyText.js +1 -1
- package/lib/module/components/BrandMark.js +1 -1
- package/lib/module/components/CodeInput.js +1 -1
- package/lib/module/components/EmailInput.js +1 -1
- package/lib/module/components/GoogleButton.js +1 -1
- package/lib/module/components/HeadingGroup.js +1 -1
- package/lib/module/components/LLMDataInputModal.js +1 -1
- package/lib/module/components/ModalHeader.js +1 -1
- package/lib/module/components/ModalSheet.js +1 -1
- package/lib/module/components/Onairos.js +1 -1
- package/lib/module/components/OnairosButton.js +1 -1
- package/lib/module/components/OnairosSignInButton.js +1 -1
- package/lib/module/components/Overlay.js +1 -1
- package/lib/module/components/PersonaImage.js +1 -1
- package/lib/module/components/PersonaLoadingScreen.js +1 -1
- package/lib/module/components/PersonalizationConsentScreen.js +1 -1
- package/lib/module/components/PinCreationScreen.js +1 -1
- package/lib/module/components/PinInput.js +1 -1
- package/lib/module/components/PlatformConnectorsStep.js +1 -1
- package/lib/module/components/PlatformList.js +1 -1
- package/lib/module/components/PlatformToggle.js +1 -1
- package/lib/module/components/PrimaryButton.js +1 -1
- package/lib/module/components/SignInMatchAnimation.js +1 -1
- package/lib/module/components/SignInStep.js +1 -1
- package/lib/module/components/UniversalOnboarding.js +1 -1
- package/lib/module/components/VerificationStep.js +1 -1
- package/lib/module/components/WelcomeScreen.js +1 -1
- package/lib/module/components/icons/Basicproficon.js +1 -1
- package/lib/module/components/icons/Basicprofile.js +1 -1
- package/lib/module/components/icons/Checkbox.js +1 -1
- package/lib/module/components/icons/Checkmark.js +1 -1
- package/lib/module/components/icons/Contentanalysis.js +1 -1
- package/lib/module/components/icons/Contenticon.js +1 -1
- package/lib/module/components/icons/EnochE.js +1 -1
- package/lib/module/components/icons/Personalityicon.js +1 -1
- package/lib/module/components/icons/Personalityprofile.js +1 -1
- package/lib/module/components/icons/Personalitytraits.js +1 -1
- package/lib/module/components/icons/Userpreferences.js +1 -1
- package/lib/module/components/onboarding/OAuthWebView.js +1 -1
- package/lib/module/components/onboarding/OnboardingHeader.js +1 -1
- package/lib/module/components/onboarding/PinInput.js +1 -1
- package/lib/module/components/onboarding/PlatformConnector.js +1 -1
- package/lib/module/config/api.js +1 -1
- package/lib/module/constants/index.js +1 -1
- package/lib/module/context/AuthContext.js +1 -1
- package/lib/module/hooks/useConnectedAccounts.js +1 -1
- package/lib/module/hooks/useConnections.js +1 -1
- package/lib/module/hooks/useCredentials.js +1 -1
- package/lib/module/hooks/useUserConnections.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/services/apiClient.js +1 -1
- package/lib/module/services/apiKeyService.js +898 -1
- package/lib/module/services/authService.js +602 -1
- package/lib/module/services/biometricPinService.js +1 -1
- package/lib/module/services/chatGPTConversationExtractor.js +1 -1
- package/lib/module/services/chatGPTConversationService.js +1 -1
- package/lib/module/services/claudeConversationExtractor.js +1 -1
- package/lib/module/services/claudeConversationService.js +1 -1
- package/lib/module/services/connectedAccountsService.js +1 -1
- package/lib/module/services/googleAuthService.js +1 -1
- package/lib/module/services/hingeDataExtractor.js +1 -1
- package/lib/module/services/hingeDataService.js +1 -1
- package/lib/module/services/imageCompressionService.js +1 -1
- package/lib/module/services/instagramDataExtractor.js +1 -1
- package/lib/module/services/instagramDataService.js +1 -1
- package/lib/module/services/jwtStorageService.js +1 -1
- package/lib/module/services/linkedinDOMExtractor.js +1 -1
- package/lib/module/services/linkedinProfileService.js +1 -1
- package/lib/module/services/linkedinScrapingService.js +1 -1
- package/lib/module/services/llmDataStorage.js +1 -1
- package/lib/module/services/mobileTrainingService.js +1 -1
- package/lib/module/services/oauthService.js +381 -1
- package/lib/module/services/pinEncryptionService.js +1 -1
- package/lib/module/services/pinStorageUtils.js +1 -1
- package/lib/module/services/platformAuthService.js +1 -1
- package/lib/module/services/sephoraDataExtractor.js +1 -1
- package/lib/module/services/sephoraDataService.js +1 -1
- package/lib/module/services/storageService.js +1 -1
- package/lib/module/services/telegramDataExtractor.js +1 -1
- package/lib/module/services/telegramDataService.js +1 -1
- package/lib/module/services/trainingApiHelpers.js +1 -1
- package/lib/module/services/userConnectionsService.js +1 -1
- package/lib/module/services/youtubeMigrationService.js +1 -1
- package/lib/module/theme/index.js +1 -1
- package/lib/module/types.js +1 -1
- package/lib/module/utils/Portal.js +1 -1
- package/lib/module/utils/api.js +1 -1
- package/lib/module/utils/assetRegistry.js +1 -1
- package/lib/module/utils/auth.js +1 -1
- package/lib/module/utils/connectorTests.js +1 -1
- package/lib/module/utils/crypto.js +1 -1
- package/lib/module/utils/debugHelper.js +1 -1
- package/lib/module/utils/encryption.js +1 -1
- package/lib/module/utils/eventUtils.js +1 -1
- package/lib/module/utils/haptics.js +1 -1
- package/lib/module/utils/networkDiagnostics.js +1 -1
- package/lib/module/utils/onairosApi.js +1 -1
- package/lib/module/utils/programmaticFlow.js +1 -1
- package/lib/module/utils/retryHelper.js +1 -1
- package/lib/module/utils/secureStorage.js +1 -1
- package/lib/module/utils/webviewScripts/chatgpt.js +1 -1
- package/lib/module/utils/webviewScripts/claude.js +1 -1
- package/lib/module/utils/webviewScripts/hinge.js +1 -1
- package/lib/module/utils/webviewScripts/index.js +1 -1
- package/lib/module/utils/webviewScripts/instagram.js +1 -1
- package/lib/module/utils/webviewScripts/linkedin.js +1 -1
- package/lib/module/utils/webviewScripts/sephora.js +1 -1
- package/lib/module/utils/webviewScripts/telegram.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1,602 @@
|
|
|
1
|
-
import AsyncStorage from'@react-native-async-storage/async-storage';import{API_CONFIG,getApiHeaders,getAuthHeaders}from'../config/api';import{getDeveloperAuthHeaders,isApiKeyInitialized}from'./apiKeyService';import{storeJWT,getJWT,clearJWT}from'./jwtStorageService';const API_BASE_URL=API_CONFIG['BASE_URL'],waitForSDKInit=async(_0x22c103=0x1f40)=>{const _0x23f414={'ocCHQ':'❌\x20[EMAIL\x20VERIFY]\x20Server\x20error:','pRStx':_0x5eef(0x0),'dlLNy':'⏳\x20[AUTH]\x20SDK\x20not\x20yet\x20initialized,\x20waiting...','OmMFk':function(_0x98fbc2,_0x158f26){return _0x98fbc2<_0x158f26;},'vJUPE':function(_0xf5e419,_0x57a6a8){return _0xf5e419-_0x57a6a8;},'nsPJt':function(_0x3622ba){return _0x3622ba();},'fTfTZ':function(_0x2e759f,_0x7fe31){return _0x2e759f===_0x7fe31;},'rdjDX':'GJrWw','jiyLD':_0x5eef(0x1),'RExIi':'❌\x20[AUTH]\x20SDK\x20did\x20not\x20initialize\x20within'};if(isApiKeyInitialized())return!![];console['log'](_0x23f414[_0x5eef(0x2)]);const _0x5724af=Date[_0x5eef(0x3)]();while(_0x23f414[_0x5eef(0x4)](_0x23f414[_0x5eef(0x5)](Date[_0x5eef(0x3)](),_0x5724af),_0x22c103)){await new Promise(_0x2580dd=>setTimeout(()=>_0x2580dd(),0x1f4));if(_0x23f414[_0x5eef(0x6)](isApiKeyInitialized))return _0x23f414['fTfTZ'](_0x23f414[_0x5eef(0x7)],_0x23f414[_0x5eef(0x7)])?(console[_0x5eef(0x8)](_0x23f414[_0x5eef(0x9)],Date['now']()-_0x5724af,'ms'),!![]):(_0x27d93e['log'](_0x23f414[_0x5eef(0xa)],_0x28c16b[_0x5eef(0xb)]||_0x45ba95['message']),{'success':![],'message':_0xe17739['error']||_0x36cc6e['message']||_0x23f414[_0x5eef(0xc)]});}return console[_0x5eef(0xb)](_0x23f414['RExIi'],_0x22c103,'ms'),![];};export const authenticateWithOnairos=async _0x4c1d2f=>{const _0x325b46={'ECFbV':_0x5eef(0xd),'ZAmHP':'nicholas.berry@onairos.uk','PqWYJ':_0x5eef(0xe),'AUDTm':_0x5eef(0xf),'GMhNl':_0x5eef(0x10),'EeyZt':_0x5eef(0x11),'gVzrq':function(_0x3a50af,_0x2b476f){return _0x3a50af(_0x2b476f);},'GQSZq':'onairos_username','OqjZC':_0x5eef(0x12),'VNEdm':'user_email','cgABH':_0x5eef(0x13),'FVIIe':_0x5eef(0x14),'zPuhM':'QDXpa','jFbzU':_0x5eef(0x15),'LwXyM':'❌\x20Onairos\x20authentication\x20error:'};try{console['log'](_0x325b46[_0x5eef(0x16)]),await _0x325b46['gVzrq'](storeJWT,_0x4c1d2f[_0x5eef(0x17)]);const _0x4a31d2=await AsyncStorage[_0x5eef(0x18)](_0x325b46['GQSZq']),_0x4a4453=_0x4a31d2||_0x4c1d2f[_0x5eef(0x19)][_0x5eef(0x1a)]('@')[0x0]||_0x325b46[_0x5eef(0x1b)];return await AsyncStorage[_0x5eef(0x1c)](_0x325b46[_0x5eef(0x1d)],_0x4a4453),await AsyncStorage[_0x5eef(0x1c)](_0x325b46['VNEdm'],_0x4c1d2f[_0x5eef(0x19)]),console[_0x5eef(0x8)](_0x325b46[_0x5eef(0x1e)],_0x4c1d2f[_0x5eef(0x17)][_0x5eef(0x1f)](0x0,0x14)+_0x5eef(0x20)),console[_0x5eef(0x8)](_0x325b46[_0x5eef(0x21)],{'email':_0x4c1d2f['email'],'username':_0x4a4453}),{'token':_0x4c1d2f['token'],'user':{'id':Date[_0x5eef(0x3)]()[_0x5eef(0x22)](),'name':_0x4a4453,'email':_0x4c1d2f['email'],'profilePicture':''}};}catch(_0x419222){if(_0x325b46[_0x5eef(0x23)]===_0x325b46[_0x5eef(0x24)]){if(!_0x4ea9bd)return _0x360594[_0x5eef(0x8)](_0x325b46['ECFbV']),![];const _0x6a2417=[_0x325b46[_0x5eef(0x25)],_0x5eef(0x26),_0x5eef(0x27),_0x325b46[_0x5eef(0x28)]],_0x3de1da=_0x6a2417[_0x5eef(0x29)](_0x721434[_0x5eef(0x2a)]());return _0x3de1da?_0x5247f3[_0x5eef(0x8)](_0x325b46[_0x5eef(0x2b)],_0x1b47dc):_0x44bb4a[_0x5eef(0x8)](_0x325b46[_0x5eef(0x2c)],_0x42d529),_0x3de1da;}else{console[_0x5eef(0xb)](_0x325b46['LwXyM'],_0x419222);throw _0x419222;}}};export const authenticateWithOnairosSignIn=async _0x1cfef5=>{const _0x14b035={'IBTdX':_0x5eef(0x2d),'tKJoQ':'SDK\x20is\x20still\x20initializing.\x20Please\x20wait\x20a\x20moment\x20and\x20try\x20again.','fajGk':function(_0x4d8319){return _0x4d8319();},'TaPNe':_0x5eef(0x2e),'icclI':function(_0x554bc6,_0x2673f6){return _0x554bc6+_0x2673f6;},'VSkZm':function(_0x7d405,_0x529163){return _0x7d405===_0x529163;},'vUpdc':_0x5eef(0x20),'ArClK':function(_0x25bc37,_0x244969){return _0x25bc37===_0x244969;},'zKtvS':_0x5eef(0x2f),'IIkdS':_0x5eef(0x30),'nqEFC':_0x5eef(0x31),'qSZQb':_0x5eef(0x32),'KMGfu':_0x5eef(0x33),'HKDmT':'✅\x20Onairos\x20sign-in\x20successful','jkuKg':_0x5eef(0x34),'BRsiZ':'No\x20authentication\x20token\x20returned\x20from\x20Onairos\x20sign-in','Xekpd':function(_0x35ef52,_0x54cd7a){return _0x35ef52(_0x54cd7a);},'FXmbd':_0x5eef(0x35),'jPSsk':'user_email','PCmEt':_0x5eef(0x36),'ikBEa':'hlwtp','EfFbJ':_0x5eef(0x37)};try{if(_0x14b035[_0x5eef(0x38)](_0x14b035[_0x5eef(0x39)],_0x14b035['IIkdS']))return _0x544507['log'](_0x14b035[_0x5eef(0x3a)],_0x547eb6[_0x5eef(0xb)]||_0x4841c0[_0x5eef(0x3b)]),{'success':![],'message':_0x12fcf0[_0x5eef(0xb)]||_0x137251['message']||'Invalid\x20verification\x20code'};else{console[_0x5eef(0x8)](_0x14b035['nqEFC']);const _0x54c7c9=await fetch(API_BASE_URL+'/login/signin',{'method':'POST','headers':getApiHeaders(),'body':JSON[_0x5eef(0x3c)](_0x1cfef5)});if(!_0x54c7c9['ok']){if(_0x14b035[_0x5eef(0x38)](_0x14b035[_0x5eef(0x3d)],'KLglH')){const _0x94abab=await _0x54c7c9[_0x5eef(0x3e)]();throw new Error(_0x94abab['error']||_0x14b035['KMGfu']);}else return{'success':![],'message':_0x14b035[_0x5eef(0x3f)]};}const _0x12da7d=await _0x54c7c9[_0x5eef(0x3e)]();console[_0x5eef(0x8)](_0x14b035[_0x5eef(0x40)]);if(!_0x12da7d[_0x5eef(0x17)]){if(_0x14b035['ArClK']('csCYA',_0x14b035['jkuKg']))throw new Error(_0x14b035[_0x5eef(0x41)]);else{var _0x46bf34;_0x5be4d3=_0x14b035[_0x5eef(0x42)](_0x4594d0),_0x17a191[_0x5eef(0x8)](_0x14b035['TaPNe'],_0x14b035[_0x5eef(0x43)](_0x14b035['VSkZm'](_0x46bf34=_0x40af0b[_0x5eef(0x44)],null)||_0x14b035['VSkZm'](_0x46bf34,void 0x0)?void 0x0:_0x46bf34['substring'](0x0,0x14),_0x14b035['vUpdc']));}}return await _0x14b035[_0x5eef(0x45)](storeJWT,_0x12da7d[_0x5eef(0x17)]),_0x12da7d[_0x5eef(0x46)]&&await AsyncStorage[_0x5eef(0x1c)](_0x14b035[_0x5eef(0x47)],_0x12da7d['username']),await AsyncStorage['setItem'](_0x14b035[_0x5eef(0x48)],_0x1cfef5[_0x5eef(0x19)]),console['log'](_0x14b035['PCmEt'],_0x12da7d[_0x5eef(0x17)][_0x5eef(0x1f)](0x0,0x14)+_0x5eef(0x20)),{'token':_0x12da7d[_0x5eef(0x17)],'user':{'id':Date[_0x5eef(0x3)]()['toString'](),'name':_0x12da7d[_0x5eef(0x46)],'email':_0x1cfef5[_0x5eef(0x19)],'profilePicture':''}};}}catch(_0x27e804){if(_0x14b035[_0x5eef(0x49)](_0x14b035[_0x5eef(0x4a)],_0x14b035[_0x5eef(0x4b)]))_0x48b6b7[_0x5eef(0x8)]('✅\x20['+_0x338cb6+']\x20Authentication\x20validated\x20for\x20API\x20call');else{console[_0x5eef(0xb)](_0x5eef(0x4c),_0x27e804);throw _0x27e804;}}};export const authenticateWithApple=async _0x15ce78=>{const _0xc5d447={'EwRKj':_0x5eef(0x1),'wJIJX':function(_0x14022c,_0x22f100){return _0x14022c-_0x22f100;},'IAmdG':_0x5eef(0x12),'IdKQG':_0x5eef(0x4d),'NLQLc':function(_0x595ab4){return _0x595ab4();},'vfVme':_0x5eef(0x4e),'uXviS':function(_0x34a048,_0x44af97){return _0x34a048!==_0x44af97;},'weIYw':_0x5eef(0x4f),'kIQPv':'No\x20authentication\x20token\x20returned\x20from\x20Apple\x20auth','wVrBr':function(_0x20b57d,_0x3652b3){return _0x20b57d(_0x3652b3);},'sZRkO':function(_0x3e535c,_0x593abb){return _0x3e535c===_0x593abb;},'WkHhU':function(_0x48b981,_0x398d57){return _0x48b981===_0x398d57;},'rddbL':_0x5eef(0x50),'XURFN':function(_0x14885,_0x5c2e97){return _0x14885===_0x5c2e97;},'diLbr':function(_0x4324e3,_0x33f145){return _0x4324e3===_0x33f145;},'QXWQz':function(_0x5211a9,_0x269be9){return _0x5211a9===_0x269be9;},'yQxNZ':'❌\x20Apple\x20authentication\x20error:'};try{var _0x48a77c,_0x2d14c1,_0xb28d4c,_0x128cb3;const _0x3ee522=_0x15ce78['fullName']?((_0x15ce78[_0x5eef(0x51)]['givenName']||'')+'\x20'+(_0x15ce78[_0x5eef(0x51)][_0x5eef(0x52)]||''))['trim']():_0xc5d447[_0x5eef(0x53)];console['log'](_0xc5d447['IdKQG']);const _0x501c2b=await fetch(API_BASE_URL+_0x5eef(0x54),{'method':'POST','headers':_0xc5d447['NLQLc'](getApiHeaders),'body':JSON[_0x5eef(0x3c)]({'idToken':_0x15ce78[_0x5eef(0x55)],'nonce':_0x15ce78['nonce'],'name':_0x3ee522,'email':_0x15ce78[_0x5eef(0x19)]})});if(!_0x501c2b['ok']){const _0x2e52bb=await _0x501c2b[_0x5eef(0x3e)]();throw new Error(_0x2e52bb[_0x5eef(0xb)]||_0xc5d447[_0x5eef(0x56)]);}const _0x490757=await _0x501c2b[_0x5eef(0x3e)]();console[_0x5eef(0x8)](_0x5eef(0x57));if(!_0x490757[_0x5eef(0x17)]){if(_0xc5d447['uXviS'](_0xc5d447['weIYw'],'eWAhz'))return _0x407a3c[_0x5eef(0x8)](_0xc5d447[_0x5eef(0x58)],_0xc5d447[_0x5eef(0x59)](_0x3f3ffc['now'](),_0x24ce89),'ms'),!![];else throw new Error(_0xc5d447[_0x5eef(0x5a)]);}await _0xc5d447[_0x5eef(0x5b)](storeJWT,_0x490757[_0x5eef(0x17)]);const _0x31c803=(_0xc5d447[_0x5eef(0x5c)](_0x48a77c=_0x490757[_0x5eef(0x5d)],null)||_0xc5d447[_0x5eef(0x5e)](_0x48a77c,void 0x0)?void 0x0:_0x48a77c[_0x5eef(0x46)])||_0x490757[_0x5eef(0x46)]||_0x3ee522;await AsyncStorage['setItem'](_0x5eef(0x35),_0x31c803);const _0x596d27=(_0xc5d447[_0x5eef(0x5c)](_0x2d14c1=_0x490757[_0x5eef(0x5d)],null)||_0x2d14c1===void 0x0?void 0x0:_0x2d14c1[_0x5eef(0x19)])||_0x15ce78[_0x5eef(0x19)]||_0x5eef(0x5f)+_0x15ce78['user']+'@privaterelay.apple.com';return await AsyncStorage[_0x5eef(0x1c)](_0xc5d447[_0x5eef(0x60)],_0x596d27),console['log'](_0x5eef(0x61),_0x490757[_0x5eef(0x17)][_0x5eef(0x1f)](0x0,0x14)+_0x5eef(0x20)),{'success':!![],'token':_0x490757[_0x5eef(0x17)],'user':{'id':(_0xc5d447[_0x5eef(0x5e)](_0xb28d4c=_0x490757[_0x5eef(0x5d)],null)||_0xc5d447[_0x5eef(0x62)](_0xb28d4c,void 0x0)?void 0x0:_0xb28d4c['id'])||'','odeanId':_0xc5d447[_0x5eef(0x63)](_0x128cb3=_0x490757[_0x5eef(0x5d)],null)||_0xc5d447[_0x5eef(0x64)](_0x128cb3,void 0x0)?void 0x0:_0x128cb3[_0x5eef(0x65)],'email':_0x596d27,'username':_0x31c803},'isNewUser':_0x490757[_0x5eef(0x66)]||![]};}catch(_0x3b88e0){console['error'](_0xc5d447['yQxNZ'],_0x3b88e0);throw _0x3b88e0;}};export const saveAuthToken=async _0x11b866=>{const _0x258708={'bBunp':_0x5eef(0x67),'PNUjs':function(_0x2bcde6,_0x49d47d){return _0x2bcde6!==_0x49d47d;},'qGHfY':_0x5eef(0x68),'xcgjq':'Error\x20saving\x20auth\x20token:'};try{await AsyncStorage[_0x5eef(0x1c)]('auth_token',_0x11b866);}catch(_0xde5168){if(_0x258708[_0x5eef(0x69)](_0x258708[_0x5eef(0x6a)],'IqYtF')){_0x4ecb20['error'](_0x258708[_0x5eef(0x6b)],_0x179bd7);throw _0x3c9b77;}else{console[_0x5eef(0xb)](_0x258708[_0x5eef(0x6c)],_0xde5168);throw _0xde5168;}}};export const debugAuthStorage=async()=>{const _0x23d41d={'fIGIc':_0x5eef(0x6d),'hyNyI':_0x5eef(0x6e),'cGdMh':_0x5eef(0x6f),'drywp':_0x5eef(0x70),'JVKhi':_0x5eef(0x71),'thcdS':'🔑\x20auth_method:','jJqik':_0x5eef(0x72)};console[_0x5eef(0x8)](_0x23d41d[_0x5eef(0x73)]);const _0x298fe1=await AsyncStorage[_0x5eef(0x18)](_0x5eef(0x74)),_0x2c8f95=await AsyncStorage[_0x5eef(0x18)](_0x5eef(0x50)),_0x2e0403=await AsyncStorage['getItem']('onairos_username'),_0x27353c=await AsyncStorage[_0x5eef(0x18)](_0x23d41d[_0x5eef(0x75)]);console['log'](_0x5eef(0x76),_0x298fe1?'\x22'+_0x298fe1[_0x5eef(0x1f)](0x0,0x1e)+_0x5eef(0x77):_0x23d41d['cGdMh']),console['log'](_0x23d41d['drywp'],_0x2c8f95?'\x22'+_0x2c8f95+'\x22':_0x23d41d[_0x5eef(0x78)]),console['log'](_0x23d41d[_0x5eef(0x79)],_0x2e0403?'\x22'+_0x2e0403+'\x22':_0x23d41d['cGdMh']),console[_0x5eef(0x8)](_0x23d41d['thcdS'],_0x27353c?'\x22'+_0x27353c+'\x22':_0x23d41d[_0x5eef(0x78)]);if(_0x298fe1){const _0x4750e3=_0x298fe1[_0x5eef(0x1a)]('.')[_0x5eef(0x7a)]===0x3;console[_0x5eef(0x8)](_0x23d41d[_0x5eef(0x7b)],_0x4750e3);}};export const clearAllAuthTokens=async()=>{const _0x1c4738={'VYCKa':function(_0x135195){return _0x135195();},'hYvJD':'onairos_username','vlvwy':_0x5eef(0x7c),'yagwG':_0x5eef(0x7d)};console['log'](_0x5eef(0x7e)),await _0x1c4738[_0x5eef(0x7f)](clearJWT),await AsyncStorage['multiRemove']([_0x5eef(0x50),_0x1c4738[_0x5eef(0x80)],_0x5eef(0x6e),_0x1c4738[_0x5eef(0x81)]]),console['log'](_0x1c4738[_0x5eef(0x82)]);};function _0xef84(){const _0x48222a=['Failed\x20to\x20send\x20verification\x20code','✅\x20[AUTH]\x20SDK\x20initialized\x20after','dlLNy','now','OmMFk','vJUPE','nsPJt','rdjDX','log','jiyLD','ocCHQ','error','pRStx','🔒\x20[Admin\x20Check]\x20No\x20email\x20provided','admin@onairos.uk','🔑\x20[Admin\x20Check]\x20Admin\x20access\x20granted\x20for:','🚫\x20[Admin\x20Check]\x20No\x20admin\x20access\x20for:','🔑\x20Authenticating\x20with\x20Onairos...','Onairos\x20User','🔑\x20Onairos\x20auth\x20token\x20stored:','👤\x20User\x20info:','oOsIA','EeyZt','token','getItem','email','split','OqjZC','setItem','GQSZq','cgABH','substring','...','FVIIe','toString','zPuhM','jFbzU','ZAmHP','zion.darko@onairos.uk','admin@enoch.events','PqWYJ','includes','toLowerCase','AUDTm','GMhNl','❌\x20[CODE\x20VERIFY]\x20Server\x20error:','📧\x20[EMAIL\x20VERIFY]\x20Headers\x20OK,\x20key:','ZJMYV','YimtR','🔑\x20Signing\x20in\x20with\x20Onairos\x20via\x20/login/signin\x20endpoint...','KLglH','Onairos\x20sign-in\x20failed','csCYA','onairos_username','🔑\x20Onairos\x20sign-in\x20token\x20stored:','DnHFk','ArClK','zKtvS','IBTdX','message','stringify','qSZQb','json','tKJoQ','HKDmT','BRsiZ','fajGk','icclI','Authorization','Xekpd','username','FXmbd','jPSsk','VSkZm','ikBEa','EfFbJ','❌\x20Onairos\x20sign-in\x20error:','🍎\x20Authenticating\x20with\x20Apple\x20via\x20generic\x20SDK\x20endpoint...','Apple\x20authentication\x20failed','eWAhz','user_email','fullName','familyName','IAmdG','/register/apple','identityToken','vfVme','✅\x20Apple\x20authentication\x20successful','EwRKj','wJIJX','kIQPv','wVrBr','sZRkO','user','WkHhU','apple_','rddbL','🔑\x20Apple\x20auth\x20token\x20stored:','XURFN','diLbr','QXWQz','odeanId','isNewUser','❌\x20Apple\x20authentication\x20error:','IqYtF','PNUjs','qGHfY','bBunp','xcgjq','🔍\x20[AUTH\x20STORAGE\x20DEBUG]\x20Checking\x20all\x20auth-related\x20storage:','auth_method','null','🔑\x20user_email:','🔑\x20onairos_username:','🔍\x20Token\x20appears\x20to\x20be\x20valid\x20JWT:','fIGIc','sdk_jwt_token','hyNyI','🔑\x20sdk_jwt_token:','...\x22','cGdMh','JVKhi','length','jJqik','onairos_user','✅\x20[AUTH]\x20All\x20auth\x20tokens\x20and\x20data\x20cleared','🧹\x20[AUTH]\x20Clearing\x20all\x20auth\x20tokens...','VYCKa','hYvJD','vlvwy','yagwG','❌\x20Onairos\x20authentication\x20error:','pQzUb','rcyoY','✅\x20[AUTH]\x20Found\x20JWT\x20token:','cpJqA','❌\x20[AUTH]\x20Error\x20during\x20token\x20retrieval:','cSacl','TIxrD','fEboS','Zgiko','yLlUa','LyjkZ','vzfXU','✅\x20[TOKEN\x20VERIFY]\x20Token\x20is\x20valid','jWnyF','auth_token','ismCp','removeItem','STtCO','KnfNw','vLYJq','jUvya','OEhav','ivnfa','❌\x20[AUTH\x20VALIDATION]\x20Error\x20checking\x20authentication\x20status:','Vhqiy','FnJSp','KjdGA','cXpeM','tbfRn','warn','⚠️\x20[',']\x20No\x20valid\x20authentication\x20available\x20-\x20API\x20call\x20may\x20return\x20limited\x20data','riLJV','Lrhig','✅\x20[',']\x20Authentication\x20validated\x20for\x20API\x20call','fNZZv','✅\x20[EMAIL\x20VERIFY]\x20Verification\x20code\x20sent\x20successfully','tBGJG','NFIoZ','mFpEq','🔒\x20[TOKEN\x20VERIFY]\x20No\x20token\x20available\x20for\x20verification','🔒\x20[TOKEN\x20VERIFY]\x20Token\x20preview:','VxtYJ','hbaDo','GrQKj','SvAaE','❌\x20[TOKEN\x20VERIFY]\x20Token\x20verification\x20failed:','LoOcd','❌\x20[TOKEN\x20VERIFY]\x20Token\x20verification\x20error:','FZUTa','nzEsX','CulCp','QpiUA','SZzZH','KEzFt','🔒\x20[TOKEN\x20VERIFY]\x20Verifying\x20token\x20with\x20backend...','DZcfP','sXUqx','eXZSQ','🔒\x20[TOKEN\x20VERIFY]\x20Verification\x20response\x20status:','status','luaRe','mgLRa','WNOLq','JseMq','UpYWh','ooaYG','lJBFu','nicholas.berry@onairos.uk','ihsaI','yxdOW','true','user_admin_status','yPxCW','xNKpF','Error\x20getting\x20admin\x20status:','qqkqj','cpvFE','CfOlY','lFClz','sewlx','TvKHH','UoWxm','fDLag','vtiac','KCyfA','Error\x20getting\x20Onairos\x20username:','TGpIL','pfzHU','XxeHH','RxAOL','adjMy','Error\x20saving\x20Onairos\x20username:','❌\x20[EMAIL\x20VERIFY]\x20Failed\x20to\x20get\x20auth\x20headers:','📧\x20[EMAIL\x20VERIFY]\x20Sending\x20verification\x20code\x20to:','SDK\x20is\x20still\x20initializing.\x20Please\x20wait\x20a\x20moment\x20and\x20try\x20again.','XAcsg','📧\x20[EMAIL\x20VERIFY]\x20Response\x20status:','lpDzX','TIMEOUT','CLCcZ','❌\x20[EMAIL\x20VERIFY]\x20All\x20retries\x20exhausted:','Network\x20error.\x20Please\x20try\x20again.','/email/verification','BrOqu','📧\x20[EMAIL\x20VERIFY]\x20URL:','NeirA','uwZco','huMvw','cAPtB','KKjzh','emJsc','BgVdC','aUJeb','📧\x20[EMAIL\x20VERIFY]\x20Attempt\x20','QncxE','abort','signal','DxxcI','success','ygpVz','SDK\x20not\x20properly\x20initialized.\x20Please\x20restart\x20the\x20app\x20and\x20try\x20again.','❌\x20[EMAIL\x20VERIFY]\x20Server\x20error:','name','AbortError','❌\x20[EMAIL\x20VERIFY]\x20Attempt\x20','\x20failed:','LVeOf','McuiP','zpOvU','UCTBx','zhSPj','bKvUk','eBSdu','YlUqc','🔄\x20[EMAIL\x20VERIFY]\x20Retrying\x20in\x20','ms...','heyPQ','Network\x20error.\x20Please\x20check\x20your\x20connection\x20and\x20try\x20again.','ausct','No\x20authentication\x20token\x20returned\x20from\x20Onairos\x20sign-in','🔍\x20[CODE\x20VERIFY]\x20Headers\x20OK','eFIwv','❌\x20[CODE\x20VERIFY]\x20Failed\x20to\x20get\x20auth\x20headers:','IdoDO','🔍\x20[CODE\x20VERIFY]\x20Response\x20status:','aOOro','✅\x20[CODE\x20VERIFY]\x20Email\x20verification\x20successful','returning_user','Invalid\x20verification\x20code','rcTvK','❌\x20[CODE\x20VERIFY]\x20All\x20retries\x20exhausted:','Verification\x20failed.\x20Please\x20check\x20your\x20connection\x20and\x20try\x20again.','gjTnU','kvWnF','EPmgI','aYNbl','AsyDk','lfkjC','mLCWD','yqZdf','odKHY','wbAns','NYkrV','🔍\x20[CODE\x20VERIFY]\x20Attempt\x20','AYpIA','WRisN','mUWpV','swIYP','jwtToken','qFquR','ZrLTr','rIxIM','accountInfo','existingUserData','flowType','WJObM','iCbqD','userName','QRhZr','hxDhv','iFJXP','enochInstructions','FmXeY','katsN','❌\x20[CODE\x20VERIFY]\x20Attempt\x20','QHevD','soNXO','DwxdU','gWJKs','KptOL','fUMVo','plAWa'];_0xef84=function(){return _0x48222a;};return _0xef84();}export const getAuthToken=async()=>{const _0x575d19={'WidjX':_0x5eef(0x83),'cSacl':function(_0x5ddef2){return _0x5ddef2();},'TIxrD':function(_0x383910,_0x5620a1){return _0x383910!==_0x5620a1;},'fEboS':_0x5eef(0x84),'Zgiko':_0x5eef(0x85),'yLlUa':_0x5eef(0x86),'gczUd':'❌\x20[AUTH]\x20No\x20valid\x20JWT\x20token\x20found','NjRfI':function(_0x527d45,_0x587285){return _0x527d45===_0x587285;},'LyjkZ':_0x5eef(0x87),'jWnyF':_0x5eef(0x88)};try{const _0x2590ef=await _0x575d19[_0x5eef(0x89)](getJWT);if(_0x2590ef){if(_0x575d19[_0x5eef(0x8a)](_0x575d19[_0x5eef(0x8b)],_0x575d19[_0x5eef(0x8c)]))return console[_0x5eef(0x8)](_0x575d19[_0x5eef(0x8d)],_0x2590ef[_0x5eef(0x1f)](0x0,0x14)+_0x5eef(0x20)),_0x2590ef;else{_0x463f6b[_0x5eef(0xb)](_0x575d19['WidjX'],_0x5e0cd7);throw _0x356001;}}return console['warn'](_0x575d19['gczUd']),null;}catch(_0x2b656d){return _0x575d19['NjRfI'](_0x575d19[_0x5eef(0x8e)],_0x5eef(0x8f))?(_0x1cd512['log'](_0x5eef(0x90)),!![]):(console[_0x5eef(0xb)](_0x575d19[_0x5eef(0x91)],_0x2b656d),null);}};export const removeAuthToken=async()=>{const _0x3bfbdc={'vLYJq':'Error\x20removing\x20auth\x20token:','xcXdF':_0x5eef(0x92),'STtCO':function(_0x36cfb7,_0x2fe0d2){return _0x36cfb7===_0x2fe0d2;},'KnfNw':_0x5eef(0x93)};try{await AsyncStorage[_0x5eef(0x94)](_0x3bfbdc['xcXdF']);}catch(_0x1f5c69){_0x3bfbdc[_0x5eef(0x95)](_0x3bfbdc[_0x5eef(0x96)],_0x3bfbdc[_0x5eef(0x96)])?console[_0x5eef(0xb)](_0x3bfbdc[_0x5eef(0x97)],_0x1f5c69):_0x498768[_0x5eef(0xb)](_0x3bfbdc[_0x5eef(0x97)],_0x28beb8);}};export const isAuthenticated=async()=>{const _0x38faac={'jUvya':function(_0x3fc107){return _0x3fc107();},'OEhav':function(_0x45c9a5,_0x164888){return _0x45c9a5!==_0x164888;},'ivnfa':function(_0x2771f2,_0x24c3f8){return _0x2771f2>_0x24c3f8;}};try{const _0x5196cc=await _0x38faac[_0x5eef(0x98)](getAuthToken);return _0x38faac[_0x5eef(0x99)](_0x5196cc,null)&&_0x38faac[_0x5eef(0x9a)](_0x5196cc[_0x5eef(0x7a)],0x32);}catch(_0x726fa){return console[_0x5eef(0xb)](_0x5eef(0x9b),_0x726fa),![];}};export const ensureAuthentication=async _0x57ab23=>{const _0x243c2a={'fNZZv':'Error\x20saving\x20auth\x20token:','cXpeM':function(_0x3caee6){return _0x3caee6();},'hqVLJ':function(_0x2021d6,_0x5ad6ca){return _0x2021d6!==_0x5ad6ca;},'tbfRn':_0x5eef(0x9c),'MtpML':_0x5eef(0x9d),'riLJV':_0x5eef(0x9e)},_0x523f33=await _0x243c2a[_0x5eef(0x9f)](isAuthenticated);if(!_0x523f33)_0x243c2a['hqVLJ'](_0x243c2a[_0x5eef(0xa0)],_0x243c2a['MtpML'])?console[_0x5eef(0xa1)](_0x5eef(0xa2)+_0x57ab23+_0x5eef(0xa3)):_0x3f1b78['error']('Error\x20saving\x20Onairos\x20username:',_0x1da1bb);else{if(_0x243c2a[_0x5eef(0xa4)]!==_0x5eef(0xa5))console[_0x5eef(0x8)](_0x5eef(0xa6)+_0x57ab23+_0x5eef(0xa7));else{_0xcfe7e8['error'](_0x243c2a[_0x5eef(0xa8)],_0x35582f);throw _0x49b9c9;}}return _0x523f33;};export const verifyToken=async()=>{const _0x714065={'CulCp':_0x5eef(0xa9),'SZzZH':'❌\x20[CODE\x20VERIFY]\x20Failed\x20to\x20get\x20auth\x20headers:','KEzFt':'SDK\x20not\x20properly\x20initialized.\x20Please\x20restart\x20the\x20app\x20and\x20try\x20again.','vfEYV':'🔒\x20[Admin\x20Check]\x20No\x20email\x20provided','FZUTa':_0x5eef(0xaa),'nzEsX':_0x5eef(0xab),'oRTHr':function(_0x1f4929){return _0x1f4929();},'QpiUA':_0x5eef(0xac),'rrrWQ':_0x5eef(0xad),'DZcfP':_0x5eef(0xae),'sXUqx':function(_0x349d55,_0x2a0e05,_0x570d30){return _0x349d55(_0x2a0e05,_0x570d30);},'eXZSQ':function(_0x53225f,_0x199728){return _0x53225f(_0x199728);},'luaRe':_0x5eef(0xaf),'mgLRa':_0x5eef(0xb0),'WNOLq':_0x5eef(0x90),'itzcM':_0x5eef(0xb1),'JseMq':_0x5eef(0xb2),'UpYWh':_0x5eef(0xb3),'ooaYG':_0x5eef(0xb4),'BeKOP':_0x5eef(0xb5)};try{if(_0x714065[_0x5eef(0xb6)]===_0x714065[_0x5eef(0xb7)])return _0x5443a2[_0x5eef(0x8)](_0x714065[_0x5eef(0xb8)]),{'success':!![]};else{const _0x2ea766=await _0x714065['oRTHr'](getAuthToken);if(!_0x2ea766)return _0x714065[_0x5eef(0xb9)]!==_0x714065[_0x5eef(0xb9)]?(_0x1a4f4b[_0x5eef(0xb)](_0x714065[_0x5eef(0xba)],_0x47cc1f===null||_0x1c9b37===void 0x0?void 0x0:_0x6e8547[_0x5eef(0x3b)]),{'success':![],'message':_0x714065[_0x5eef(0xbb)]}):(console[_0x5eef(0xa1)](_0x714065['rrrWQ']),![]);console[_0x5eef(0x8)](_0x5eef(0xbc)),console[_0x5eef(0x8)](_0x714065[_0x5eef(0xbd)],_0x2ea766[_0x5eef(0x1f)](0x0,0x14)+_0x5eef(0x20));const _0xbd9d28=await _0x714065[_0x5eef(0xbe)](fetch,API_BASE_URL+'/api/auth/verify',{'method':'GET','headers':_0x714065[_0x5eef(0xbf)](getAuthHeaders,_0x2ea766)});console['log'](_0x5eef(0xc0),_0xbd9d28[_0x5eef(0xc1)]);if(_0xbd9d28['ok'])return _0x714065[_0x5eef(0xc2)]===_0x714065[_0x5eef(0xc3)]?(_0x48db10['error'](_0x5eef(0xb5),_0x3cfa32),![]):(console[_0x5eef(0x8)](_0x714065[_0x5eef(0xc4)]),!![]);else{if(_0x714065['itzcM']===_0x714065[_0x5eef(0xc5)])return _0x4b0249[_0x5eef(0x8)](_0x714065['vfEYV']),![];else{const _0x232645=await _0xbd9d28['text']();return console[_0x5eef(0xa1)](_0x714065[_0x5eef(0xc6)],_0xbd9d28[_0x5eef(0xc1)],_0x232645),![];}}}}catch(_0x3cd04b){if(_0x714065[_0x5eef(0xc7)]!==_0x714065[_0x5eef(0xc7)])_0x4edd56['warn'](_0x5eef(0xa2)+_0x2dd492+']\x20No\x20valid\x20authentication\x20available\x20-\x20API\x20call\x20may\x20return\x20limited\x20data');else return console['error'](_0x714065['BeKOP'],_0x3cd04b),![];}};export const isAdminEmail=_0x3dc238=>{const _0x5afa5b={'lJBFu':_0x5eef(0xd),'ihsaI':_0x5eef(0x26),'yxdOW':_0x5eef(0xe),'pRlqo':_0x5eef(0x10)};if(!_0x3dc238)return console['log'](_0x5afa5b[_0x5eef(0xc8)]),![];const _0xd20842=[_0x5eef(0xc9),_0x5afa5b[_0x5eef(0xca)],_0x5eef(0x27),_0x5afa5b[_0x5eef(0xcb)]],_0x285774=_0xd20842[_0x5eef(0x29)](_0x3dc238['toLowerCase']());return _0x285774?console[_0x5eef(0x8)](_0x5eef(0xf),_0x3dc238):console[_0x5eef(0x8)](_0x5afa5b['pRlqo'],_0x3dc238),_0x285774;};export const getAdminStatus=async()=>{const _0x8fda12={'yPxCW':function(_0x313a1d,_0x1df9cf){return _0x313a1d===_0x1df9cf;},'xNKpF':_0x5eef(0xcc)};try{const _0x21bbe9=await AsyncStorage['getItem'](_0x5eef(0xcd));return _0x8fda12[_0x5eef(0xce)](_0x21bbe9,_0x8fda12[_0x5eef(0xcf)]);}catch(_0x419aeb){return console[_0x5eef(0xb)](_0x5eef(0xd0),_0x419aeb),![];}};export const saveAdminStatus=async _0xc45075=>{const _0x539629={'vtiac':'✅\x20[AUTH]\x20Found\x20JWT\x20token:','lFClz':function(_0x28b5c3,_0x18279d){return _0x28b5c3!==_0x18279d;},'sewlx':_0x5eef(0xd1),'TvKHH':_0x5eef(0xcd),'UoWxm':_0x5eef(0xd2),'fDLag':_0x5eef(0xd3),'WezUi':'Error\x20saving\x20admin\x20status:'};try{if(_0x539629[_0x5eef(0xd4)](_0x5eef(0xd1),_0x539629[_0x5eef(0xd5)]))return _0xa49905[_0x5eef(0xb)]('❌\x20[AUTH]\x20Error\x20during\x20token\x20retrieval:',_0x55d6dc),null;else await AsyncStorage[_0x5eef(0x1c)](_0x539629[_0x5eef(0xd6)],_0xc45075[_0x5eef(0x22)]());}catch(_0x3dbae2){if(_0x539629['lFClz'](_0x539629[_0x5eef(0xd7)],_0x539629[_0x5eef(0xd8)]))console[_0x5eef(0xb)](_0x539629['WezUi'],_0x3dbae2);else return _0x867dd8[_0x5eef(0x8)](_0x539629[_0x5eef(0xd9)],_0x381389[_0x5eef(0x1f)](0x0,0x14)+_0x5eef(0x20)),_0x564f19;}};export const getOnairosUsername=async()=>{const _0x5b2643={'XxeHH':_0x5eef(0x9b),'TGpIL':function(_0x42081d,_0x56b607){return _0x42081d!==_0x56b607;},'pfzHU':_0x5eef(0xda),'RxAOL':_0x5eef(0x35),'adjMy':_0x5eef(0xdb)};try{return _0x5b2643[_0x5eef(0xdc)](_0x5b2643[_0x5eef(0xdd)],_0x5b2643[_0x5eef(0xdd)])?(_0x3494d7[_0x5eef(0xb)](_0x5b2643[_0x5eef(0xde)],_0x326376),![]):await AsyncStorage[_0x5eef(0x18)](_0x5b2643[_0x5eef(0xdf)]);}catch(_0x270d4b){return console[_0x5eef(0xb)](_0x5b2643[_0x5eef(0xe0)],_0x270d4b),null;}};function _0x5eef(_0xef844b,_0x5eef9c){_0xef844b=_0xef844b-0x0;const _0x5e26b8=_0xef84();let _0x493870=_0x5e26b8[_0xef844b];return _0x493870;}export const saveOnairosUsername=async _0x420d80=>{const _0x181aad={'rgxrX':_0x5eef(0xe1)};try{await AsyncStorage['setItem']('onairos_username',_0x420d80);}catch(_0x24b603){console[_0x5eef(0xb)](_0x181aad['rgxrX'],_0x24b603);}};export const sendEmailVerificationCode=async _0x1a9d95=>{const _0x575402={'zpOvU':function(_0x2e571b,_0x3651b7){return _0x2e571b===_0x3651b7;},'cAPtB':_0x5eef(0xe2),'WiULU':_0x5eef(0xd0),'BrOqu':_0x5eef(0xe3),'uwZco':function(_0x228311){return _0x228311();},'NeirA':_0x5eef(0xe4),'FXbPd':function(_0x1c2764,_0x4897f0){return _0x1c2764+_0x4897f0;},'NONTx':function(_0x8b956f,_0x11144){return _0x8b956f===_0x11144;},'huMvw':_0x5eef(0x20),'ZcCOT':function(_0x183ce4,_0x3daeec){return _0x183ce4!==_0x3daeec;},'aXBEN':_0x5eef(0xe5),'KKjzh':function(_0x20970c,_0x55d6b4){return _0x20970c===_0x55d6b4;},'emJsc':function(_0x4361b9,_0x31e3af){return _0x4361b9===_0x31e3af;},'BgVdC':'SDK\x20not\x20properly\x20initialized.\x20Please\x20restart\x20the\x20app\x20and\x20try\x20again.','aUJeb':'request','QncxE':function(_0x40ce81,_0x270bb1,_0x117938){return _0x40ce81(_0x270bb1,_0x117938);},'DxxcI':_0x5eef(0xe6),'ygpVz':'✅\x20[EMAIL\x20VERIFY]\x20Verification\x20code\x20sent\x20successfully','WGDhx':'bjESb','VfiEP':_0x5eef(0xe7),'lsjVA':'Failed\x20to\x20send\x20verification\x20code','LVeOf':_0x5eef(0xe8),'McuiP':function(_0x5cbce0,_0x3e4d53){return _0x5cbce0===_0x3e4d53;},'UCTBx':function(_0x336a05,_0x4d35f1){return _0x336a05<_0x4d35f1;},'zhSPj':function(_0x441777,_0x2d456c){return _0x441777!==_0x2d456c;},'bKvUk':_0x5eef(0xe9),'eBSdu':'mrDNw','YlUqc':function(_0x553a1e,_0x17dfb1){return _0x553a1e*_0x17dfb1;},'heyPQ':_0x5eef(0xea),'ausct':_0x5eef(0xeb)},_0xa1f1f6=API_BASE_URL+_0x5eef(0xec);console[_0x5eef(0x8)](_0x575402[_0x5eef(0xed)],_0x1a9d95),console[_0x5eef(0x8)](_0x5eef(0xee),_0xa1f1f6);const _0x1483de=await _0x575402['uwZco'](waitForSDKInit);if(!_0x1483de)return{'success':![],'message':_0x575402[_0x5eef(0xef)]};let _0x31f97b;try{var _0x31f384;_0x31f97b=_0x575402[_0x5eef(0xf0)](getDeveloperAuthHeaders),console[_0x5eef(0x8)](_0x5eef(0x2e),_0x575402['FXbPd'](_0x575402['zpOvU'](_0x31f384=_0x31f97b[_0x5eef(0x44)],null)||_0x575402['NONTx'](_0x31f384,void 0x0)?void 0x0:_0x31f384[_0x5eef(0x1f)](0x0,0x14),_0x575402[_0x5eef(0xf1)]));}catch(_0x591efc){if(_0x575402['ZcCOT'](_0x575402['aXBEN'],_0x575402['aXBEN'])){const _0x156898=_0x575402['zpOvU'](_0x15912d[_0x5eef(0x1a)]('.')[_0x5eef(0x7a)],0x3);_0x730359[_0x5eef(0x8)](_0x5eef(0x72),_0x156898);}else return console[_0x5eef(0xb)](_0x575402[_0x5eef(0xf2)],_0x575402[_0x5eef(0xf3)](_0x591efc,null)||_0x575402[_0x5eef(0xf4)](_0x591efc,void 0x0)?void 0x0:_0x591efc['message']),{'success':![],'message':_0x575402[_0x5eef(0xf5)]};}const _0x37e40d=JSON[_0x5eef(0x3c)]({'email':_0x1a9d95,'action':_0x575402[_0x5eef(0xf6)]}),_0x1d07fa=0x3;for(let _0x4955c9=0x1;_0x4955c9<=_0x1d07fa;_0x4955c9++){try{console[_0x5eef(0x8)](_0x5eef(0xf7)+_0x4955c9+'/'+_0x1d07fa+_0x5eef(0x20));const _0x58d806=new AbortController(),_0x18aea2=_0x575402[_0x5eef(0xf8)](setTimeout,()=>_0x58d806[_0x5eef(0xf9)](),0x3a98),_0x3d118e=await _0x575402['QncxE'](fetch,_0xa1f1f6,{'method':'POST','headers':_0x31f97b,'body':_0x37e40d,'signal':_0x58d806[_0x5eef(0xfa)]});clearTimeout(_0x18aea2),console[_0x5eef(0x8)](_0x575402[_0x5eef(0xfb)],_0x3d118e[_0x5eef(0xc1)]);const _0x293614=await _0x3d118e[_0x5eef(0x3e)]();return _0x3d118e['ok']&&_0x293614[_0x5eef(0xfc)]?(console['log'](_0x575402[_0x5eef(0xfd)]),{'success':!![]}):_0x575402[_0x5eef(0xf3)](_0x575402['WGDhx'],_0x575402['VfiEP'])?(_0x13799c['error'](_0x575402[_0x5eef(0xf2)],_0x575402['zpOvU'](_0x35f7a7,null)||_0x2e6fc8===void 0x0?void 0x0:_0x2b4c0a['message']),{'success':![],'message':_0x5eef(0xfe)}):(console[_0x5eef(0x8)](_0x5eef(0xff),_0x293614['error']||_0x293614[_0x5eef(0x3b)]),{'success':![],'message':_0x293614[_0x5eef(0xb)]||_0x293614[_0x5eef(0x3b)]||_0x575402['lsjVA']});}catch(_0x479973){const _0x7175ad=(_0x575402['emJsc'](_0x479973,null)||_0x479973===void 0x0?void 0x0:_0x479973[_0x5eef(0x100)])===_0x5eef(0x101);console['error'](_0x5eef(0x102)+_0x4955c9+_0x5eef(0x103),_0x7175ad?_0x575402[_0x5eef(0x104)]:_0x575402[_0x5eef(0x105)](_0x479973,null)||_0x575402[_0x5eef(0x106)](_0x479973,void 0x0)?void 0x0:_0x479973[_0x5eef(0x3b)]);if(_0x575402[_0x5eef(0x107)](_0x4955c9,_0x1d07fa)){if(_0x575402[_0x5eef(0x108)](_0x575402[_0x5eef(0x109)],_0x575402[_0x5eef(0x10a)])){const _0x2dd01b=_0x575402[_0x5eef(0x10b)](0x3e8,_0x4955c9);console['log'](_0x5eef(0x10c)+_0x2dd01b+_0x5eef(0x10d)),await new Promise(_0x4740f6=>setTimeout(()=>_0x4740f6(),_0x2dd01b));continue;}else return _0x33bdbf[_0x5eef(0xb)](_0x575402['WiULU'],_0x3c8a34),![];}return console[_0x5eef(0xb)](_0x575402[_0x5eef(0x10e)],_0x575402[_0x5eef(0x106)](_0x479973,null)||_0x479973===void 0x0?void 0x0:_0x479973[_0x5eef(0x3b)]),{'success':![],'message':_0x5eef(0x10f)};}}return{'success':![],'message':_0x575402[_0x5eef(0x110)]};};export const confirmEmailVerificationCode=async(_0x309d61,_0x17a84a)=>{const _0x555d5a={'qFquR':_0x5eef(0x111),'katsN':_0x5eef(0x4c),'fUMVo':function(_0x4fea74){return _0x4fea74();},'aYNbl':_0x5eef(0x112),'gjTnU':'🔍\x20[CODE\x20VERIFY]\x20Verifying\x20code\x20for:','kvWnF':function(_0x4ea311){return _0x4ea311();},'EPmgI':_0x5eef(0x113),'AsyDk':_0x5eef(0x114),'lfkjC':function(_0xc4c91d,_0x254eb3){return _0xc4c91d===_0x254eb3;},'mLCWD':function(_0x386115,_0x55e345){return _0x386115===_0x55e345;},'yqZdf':'verify','odKHY':function(_0x309a55,_0x3e4bab){return _0x309a55<=_0x3e4bab;},'wbAns':function(_0x1eb5df,_0x27257e){return _0x1eb5df===_0x27257e;},'NYkrV':_0x5eef(0x115),'AYpIA':function(_0x8b2313,_0x1eb216,_0x4d090e){return _0x8b2313(_0x1eb216,_0x4d090e);},'WRisN':function(_0x3c18bb,_0xa8aaeb,_0x31f835){return _0x3c18bb(_0xa8aaeb,_0x31f835);},'mUWpV':function(_0x2dab94,_0x4859e0){return _0x2dab94(_0x4859e0);},'swIYP':_0x5eef(0x116),'ovjFk':_0x5eef(0x117),'ZrLTr':_0x5eef(0x118),'rIxIM':function(_0x6db2b3,_0x1ed4d1){return _0x6db2b3===_0x1ed4d1;},'WJObM':_0x5eef(0x119),'iCbqD':_0x5eef(0x50),'QRhZr':'onairos_username','hxDhv':_0x5eef(0x7c),'iFJXP':_0x5eef(0xcc),'FmXeY':_0x5eef(0x2d),'bnaRM':_0x5eef(0x11a),'SLxzg':_0x5eef(0x11b),'QHevD':function(_0x2e7081,_0x3d81f5){return _0x2e7081===_0x3d81f5;},'soNXO':function(_0x3a7878,_0x1ffe34){return _0x3a7878<_0x1ffe34;},'lmjHx':function(_0x14c62c,_0x13e7a7){return _0x14c62c*_0x13e7a7;},'DwxdU':_0x5eef(0x11c),'gWJKs':function(_0x237b87,_0x3fd143){return _0x237b87===_0x3fd143;},'KptOL':_0x5eef(0x11d),'plAWa':'Verification\x20failed.\x20Please\x20try\x20again.'};console[_0x5eef(0x8)](_0x555d5a[_0x5eef(0x11e)],_0x309d61);const _0x1743ef=await _0x555d5a[_0x5eef(0x11f)](waitForSDKInit);if(!_0x1743ef)return _0x555d5a[_0x5eef(0x120)]!==_0x555d5a[_0x5eef(0x120)]?(_0x5a4c45['error'](_0x5eef(0xdb),_0x395e28),null):{'success':![],'message':_0x5eef(0xe4)};let _0x56ed7f;try{_0x56ed7f=_0x555d5a['fUMVo'](getDeveloperAuthHeaders),console[_0x5eef(0x8)](_0x555d5a[_0x5eef(0x121)]);}catch(_0x104e50){return console['error'](_0x555d5a[_0x5eef(0x122)],_0x555d5a[_0x5eef(0x123)](_0x104e50,null)||_0x555d5a[_0x5eef(0x124)](_0x104e50,void 0x0)?void 0x0:_0x104e50[_0x5eef(0x3b)]),{'success':![],'message':_0x5eef(0xfe)};}const _0x48133a=API_BASE_URL+_0x5eef(0xec),_0x43e12c=JSON[_0x5eef(0x3c)]({'email':_0x309d61,'code':_0x17a84a,'action':_0x555d5a[_0x5eef(0x125)]}),_0x58aa2f=0x3;for(let _0x17e785=0x1;_0x555d5a[_0x5eef(0x126)](_0x17e785,_0x58aa2f);_0x17e785++){try{if(_0x555d5a[_0x5eef(0x127)](_0x5eef(0x115),_0x555d5a[_0x5eef(0x128)])){console[_0x5eef(0x8)](_0x5eef(0x129)+_0x17e785+'/'+_0x58aa2f+'...');const _0x31e6c7=new AbortController(),_0x281c1d=_0x555d5a[_0x5eef(0x12a)](setTimeout,()=>_0x31e6c7['abort'](),0x3a98),_0x226553=await _0x555d5a[_0x5eef(0x12b)](fetch,_0x48133a,{'method':'POST','headers':_0x56ed7f,'body':_0x43e12c,'signal':_0x31e6c7[_0x5eef(0xfa)]});_0x555d5a[_0x5eef(0x12c)](clearTimeout,_0x281c1d),console[_0x5eef(0x8)](_0x555d5a[_0x5eef(0x12d)],_0x226553[_0x5eef(0xc1)]);const _0x549648=await _0x226553[_0x5eef(0x3e)]();console[_0x5eef(0x8)]('🔍\x20[CODE\x20VERIFY]\x20Response\x20data:',JSON[_0x5eef(0x3c)](_0x549648));const _0x1400a7=_0x549648[_0x5eef(0x17)]||_0x549648[_0x5eef(0x12e)];if(_0x226553['ok']&&_0x549648['success']&&_0x1400a7){if(_0x555d5a['ovjFk']!==_0x555d5a['ovjFk'])throw new _0x173e0a(_0x555d5a[_0x5eef(0x12f)]);else{var _0x333540;console[_0x5eef(0x8)](_0x555d5a[_0x5eef(0x130)]);const _0x7a5dda=_0x555d5a[_0x5eef(0x131)](_0x549648['existingUser'],!![]),_0x3c1cd2=!_0x7a5dda,_0x4cc2c4=(_0x555d5a[_0x5eef(0x131)](_0x333540=_0x549648[_0x5eef(0x132)],null)||_0x555d5a['rIxIM'](_0x333540,void 0x0)?void 0x0:_0x333540[_0x5eef(0x133)])||_0x549648[_0x5eef(0x133)]||null,_0x34c1ff=_0x549648[_0x5eef(0x134)]||(_0x7a5dda?_0x555d5a[_0x5eef(0x135)]:'onboarding');await storeJWT(_0x1400a7),await AsyncStorage[_0x5eef(0x1c)](_0x555d5a[_0x5eef(0x136)],_0x309d61);const _0x3a0009=_0x549648[_0x5eef(0x137)]||_0x549648['username']||_0x309d61['split']('@')[0x0];return await AsyncStorage[_0x5eef(0x1c)](_0x555d5a[_0x5eef(0x138)],_0x3a0009),await AsyncStorage[_0x5eef(0x1c)](_0x555d5a[_0x5eef(0x139)],_0x555d5a[_0x5eef(0x13a)]),{'success':!![],'token':_0x1400a7,'username':_0x3a0009,'isNewUser':_0x3c1cd2,'flowType':_0x34c1ff,'existingUserData':_0x4cc2c4,'enochInstructions':_0x549648[_0x5eef(0x13b)]};}}else return console[_0x5eef(0x8)](_0x555d5a[_0x5eef(0x13c)],_0x549648[_0x5eef(0xb)]||_0x549648[_0x5eef(0x3b)]),{'success':![],'message':_0x549648[_0x5eef(0xb)]||_0x549648[_0x5eef(0x3b)]||_0x555d5a['bnaRM']};}else{_0x121304[_0x5eef(0xb)](_0x555d5a[_0x5eef(0x13d)],_0x373389);throw _0x432f63;}}catch(_0x3c6081){if(_0x555d5a['SLxzg']===_0x5eef(0x11b)){const _0x348693=_0x555d5a['mLCWD'](_0x555d5a[_0x5eef(0x131)](_0x3c6081,null)||_0x3c6081===void 0x0?void 0x0:_0x3c6081[_0x5eef(0x100)],_0x5eef(0x101));console['error'](_0x5eef(0x13e)+_0x17e785+'\x20failed:',_0x348693?_0x5eef(0xe8):_0x555d5a[_0x5eef(0x13f)](_0x3c6081,null)||_0x3c6081===void 0x0?void 0x0:_0x3c6081[_0x5eef(0x3b)]);if(_0x555d5a[_0x5eef(0x140)](_0x17e785,_0x58aa2f)){const _0x3822f8=_0x555d5a['lmjHx'](0x3e8,_0x17e785);console[_0x5eef(0x8)]('🔄\x20[CODE\x20VERIFY]\x20Retrying\x20in\x20'+_0x3822f8+_0x5eef(0x10d)),await new Promise(_0x382df4=>setTimeout(()=>_0x382df4(),_0x3822f8));continue;}return console[_0x5eef(0xb)](_0x555d5a[_0x5eef(0x141)],_0x3c6081===null||_0x555d5a[_0x5eef(0x142)](_0x3c6081,void 0x0)?void 0x0:_0x3c6081[_0x5eef(0x3b)]),{'success':![],'message':_0x555d5a[_0x5eef(0x143)]};}else _0x3858a8=_0x555d5a[_0x5eef(0x144)](_0x2b7301),_0x33d515[_0x5eef(0x8)](_0x555d5a[_0x5eef(0x121)]);}}return{'success':![],'message':_0x555d5a[_0x5eef(0x145)]};};
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
import { API_CONFIG, getApiHeaders, getAuthHeaders } from '../config/api';
|
|
3
|
+
import { getDeveloperAuthHeaders, isApiKeyInitialized } from './apiKeyService';
|
|
4
|
+
// CRITICAL FIX: Use static imports instead of dynamic imports to avoid Hermes transpilation issues
|
|
5
|
+
import { storeJWT, getJWT, clearJWT } from './jwtStorageService';
|
|
6
|
+
|
|
7
|
+
// API base URL
|
|
8
|
+
const API_BASE_URL = API_CONFIG.BASE_URL;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wait for SDK initialization to complete (up to maxWaitMs).
|
|
12
|
+
* Polls isApiKeyInitialized() every 500ms.
|
|
13
|
+
*/
|
|
14
|
+
const waitForSDKInit = async (maxWaitMs = 8000) => {
|
|
15
|
+
if (isApiKeyInitialized()) return true;
|
|
16
|
+
console.log('⏳ [AUTH] SDK not yet initialized, waiting...');
|
|
17
|
+
const start = Date.now();
|
|
18
|
+
while (Date.now() - start < maxWaitMs) {
|
|
19
|
+
await new Promise(resolve => setTimeout(() => resolve(), 500));
|
|
20
|
+
if (isApiKeyInitialized()) {
|
|
21
|
+
console.log('✅ [AUTH] SDK initialized after', Date.now() - start, 'ms');
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
console.error('❌ [AUTH] SDK did not initialize within', maxWaitMs, 'ms');
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Legacy AuthResponse interface - kept for backward compatibility
|
|
30
|
+
// New code should use SDKAuthResponse
|
|
31
|
+
|
|
32
|
+
// Interface for Apple authentication payload
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generic SDK Authentication Response
|
|
36
|
+
* Used by all auth methods (Google, Apple, Email)
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Authenticate with Apple
|
|
41
|
+
* @param appleAuthData Data from Apple authentication
|
|
42
|
+
* @returns Authentication response with token and user data
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Authenticate with Onairos (similar to Apple authentication)
|
|
46
|
+
* @param onairosAuthData Data from Onairos authentication
|
|
47
|
+
* @returns Authentication response with token and user data
|
|
48
|
+
*/
|
|
49
|
+
export const authenticateWithOnairos = async onairosAuthData => {
|
|
50
|
+
try {
|
|
51
|
+
console.log('🔑 Authenticating with Onairos...');
|
|
52
|
+
|
|
53
|
+
// Store the token using simplified JWT storage
|
|
54
|
+
await storeJWT(onairosAuthData.token);
|
|
55
|
+
|
|
56
|
+
// Extract username from email or use stored username
|
|
57
|
+
const storedUsername = await AsyncStorage.getItem('onairos_username');
|
|
58
|
+
const userName = storedUsername || onairosAuthData.email.split('@')[0] || 'Onairos User';
|
|
59
|
+
|
|
60
|
+
// Store username and email
|
|
61
|
+
await AsyncStorage.setItem('onairos_username', userName);
|
|
62
|
+
await AsyncStorage.setItem('user_email', onairosAuthData.email);
|
|
63
|
+
console.log('🔑 Onairos auth token stored:', `${onairosAuthData.token.substring(0, 20)}...`);
|
|
64
|
+
console.log('👤 User info:', {
|
|
65
|
+
email: onairosAuthData.email,
|
|
66
|
+
username: userName
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
token: onairosAuthData.token,
|
|
70
|
+
user: {
|
|
71
|
+
id: Date.now().toString(),
|
|
72
|
+
name: userName,
|
|
73
|
+
email: onairosAuthData.email,
|
|
74
|
+
profilePicture: ''
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('❌ Onairos authentication error:', error);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Authenticate with Onairos using the standardized /login/signin endpoint
|
|
85
|
+
* @param credentials Email and password for Onairos sign-in
|
|
86
|
+
* @returns Authentication response with token and user data
|
|
87
|
+
*/
|
|
88
|
+
export const authenticateWithOnairosSignIn = async credentials => {
|
|
89
|
+
try {
|
|
90
|
+
console.log('🔑 Signing in with Onairos via /login/signin endpoint...');
|
|
91
|
+
const response = await fetch(`${API_BASE_URL}/login/signin`, {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: getApiHeaders(),
|
|
94
|
+
body: JSON.stringify(credentials)
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
const errorData = await response.json();
|
|
98
|
+
throw new Error(errorData.error || 'Onairos sign-in failed');
|
|
99
|
+
}
|
|
100
|
+
const authData = await response.json();
|
|
101
|
+
console.log('✅ Onairos sign-in successful');
|
|
102
|
+
|
|
103
|
+
// Check for authentication token
|
|
104
|
+
if (!authData.token) {
|
|
105
|
+
throw new Error('No authentication token returned from Onairos sign-in');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Store token using simplified JWT storage
|
|
109
|
+
await storeJWT(authData.token);
|
|
110
|
+
|
|
111
|
+
// Store username from response
|
|
112
|
+
if (authData.username) {
|
|
113
|
+
await AsyncStorage.setItem('onairos_username', authData.username);
|
|
114
|
+
}
|
|
115
|
+
await AsyncStorage.setItem('user_email', credentials.email);
|
|
116
|
+
console.log('🔑 Onairos sign-in token stored:', `${authData.token.substring(0, 20)}...`);
|
|
117
|
+
return {
|
|
118
|
+
token: authData.token,
|
|
119
|
+
user: {
|
|
120
|
+
id: Date.now().toString(),
|
|
121
|
+
name: authData.username,
|
|
122
|
+
email: credentials.email,
|
|
123
|
+
profilePicture: ''
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error('❌ Onairos sign-in error:', error);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Authenticate with Apple using generic SDK endpoint
|
|
134
|
+
* NOTE: This is generic SDK auth - does NOT create EnochUser
|
|
135
|
+
* Consuming apps should call /enoch/users/register after this if needed
|
|
136
|
+
*/
|
|
137
|
+
export const authenticateWithApple = async appleAuthData => {
|
|
138
|
+
try {
|
|
139
|
+
var _authData$user, _authData$user2, _authData$user3, _authData$user4;
|
|
140
|
+
const userName = appleAuthData.fullName ? `${appleAuthData.fullName.givenName || ''} ${appleAuthData.fullName.familyName || ''}`.trim() : 'Onairos User';
|
|
141
|
+
|
|
142
|
+
// Call the generic Apple authentication endpoint - SDK route, NOT Enoch-specific
|
|
143
|
+
console.log('🍎 Authenticating with Apple via generic SDK endpoint...');
|
|
144
|
+
const appleAuthResponse = await fetch(`${API_BASE_URL}/register/apple`, {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
headers: getApiHeaders(),
|
|
147
|
+
body: JSON.stringify({
|
|
148
|
+
idToken: appleAuthData.identityToken,
|
|
149
|
+
nonce: appleAuthData.nonce,
|
|
150
|
+
name: userName,
|
|
151
|
+
email: appleAuthData.email
|
|
152
|
+
})
|
|
153
|
+
});
|
|
154
|
+
if (!appleAuthResponse.ok) {
|
|
155
|
+
const errorData = await appleAuthResponse.json();
|
|
156
|
+
throw new Error(errorData.error || 'Apple authentication failed');
|
|
157
|
+
}
|
|
158
|
+
const authData = await appleAuthResponse.json();
|
|
159
|
+
console.log('✅ Apple authentication successful');
|
|
160
|
+
|
|
161
|
+
// Check for authentication token
|
|
162
|
+
if (!authData.token) {
|
|
163
|
+
throw new Error('No authentication token returned from Apple auth');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Store token using simplified JWT storage
|
|
167
|
+
await storeJWT(authData.token);
|
|
168
|
+
|
|
169
|
+
// Store username from response
|
|
170
|
+
const username = ((_authData$user = authData.user) === null || _authData$user === void 0 ? void 0 : _authData$user.username) || authData.username || userName;
|
|
171
|
+
await AsyncStorage.setItem('onairos_username', username);
|
|
172
|
+
|
|
173
|
+
// Store email - prefer backend's email (correct @placeholder.com format) over Apple's local email
|
|
174
|
+
const userEmail = ((_authData$user2 = authData.user) === null || _authData$user2 === void 0 ? void 0 : _authData$user2.email) || appleAuthData.email || `apple_${appleAuthData.user}@privaterelay.apple.com`;
|
|
175
|
+
await AsyncStorage.setItem('user_email', userEmail);
|
|
176
|
+
console.log('🔑 Apple auth token stored:', `${authData.token.substring(0, 20)}...`);
|
|
177
|
+
return {
|
|
178
|
+
success: true,
|
|
179
|
+
token: authData.token,
|
|
180
|
+
user: {
|
|
181
|
+
id: ((_authData$user3 = authData.user) === null || _authData$user3 === void 0 ? void 0 : _authData$user3.id) || '',
|
|
182
|
+
odeanId: (_authData$user4 = authData.user) === null || _authData$user4 === void 0 ? void 0 : _authData$user4.odeanId,
|
|
183
|
+
email: userEmail,
|
|
184
|
+
username: username
|
|
185
|
+
},
|
|
186
|
+
isNewUser: authData.isNewUser || false
|
|
187
|
+
};
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error('❌ Apple authentication error:', error);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Save authentication token
|
|
196
|
+
* @param token JWT token
|
|
197
|
+
*/
|
|
198
|
+
export const saveAuthToken = async token => {
|
|
199
|
+
try {
|
|
200
|
+
await AsyncStorage.setItem('auth_token', token);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.error('Error saving auth token:', error);
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Debug function to check all auth-related storage
|
|
209
|
+
*/
|
|
210
|
+
export const debugAuthStorage = async () => {
|
|
211
|
+
console.log('🔍 [AUTH STORAGE DEBUG] Checking all auth-related storage:');
|
|
212
|
+
const sdkToken = await AsyncStorage.getItem('sdk_jwt_token');
|
|
213
|
+
const userEmail = await AsyncStorage.getItem('user_email');
|
|
214
|
+
const onairosUsername = await AsyncStorage.getItem('onairos_username');
|
|
215
|
+
const authMethod = await AsyncStorage.getItem('auth_method');
|
|
216
|
+
console.log('🔑 sdk_jwt_token:', sdkToken ? `"${sdkToken.substring(0, 30)}..."` : 'null');
|
|
217
|
+
console.log('🔑 user_email:', userEmail ? `"${userEmail}"` : 'null');
|
|
218
|
+
console.log('🔑 onairos_username:', onairosUsername ? `"${onairosUsername}"` : 'null');
|
|
219
|
+
console.log('🔑 auth_method:', authMethod ? `"${authMethod}"` : 'null');
|
|
220
|
+
|
|
221
|
+
// Check if token looks valid
|
|
222
|
+
if (sdkToken) {
|
|
223
|
+
const isValidJWT = sdkToken.split('.').length === 3;
|
|
224
|
+
console.log('🔍 Token appears to be valid JWT:', isValidJWT);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Clear all auth tokens and start fresh
|
|
230
|
+
*/
|
|
231
|
+
export const clearAllAuthTokens = async () => {
|
|
232
|
+
console.log('🧹 [AUTH] Clearing all auth tokens...');
|
|
233
|
+
await clearJWT();
|
|
234
|
+
|
|
235
|
+
// Clear other auth-related data
|
|
236
|
+
await AsyncStorage.multiRemove(['user_email', 'onairos_username', 'auth_method', 'onairos_user']);
|
|
237
|
+
console.log('✅ [AUTH] All auth tokens and data cleared');
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Get saved authentication token
|
|
242
|
+
* @returns Saved JWT token or null if not found
|
|
243
|
+
*/
|
|
244
|
+
export const getAuthToken = async () => {
|
|
245
|
+
try {
|
|
246
|
+
const token = await getJWT();
|
|
247
|
+
if (token) {
|
|
248
|
+
console.log('✅ [AUTH] Found JWT token:', `${token.substring(0, 20)}...`);
|
|
249
|
+
return token;
|
|
250
|
+
}
|
|
251
|
+
console.warn('❌ [AUTH] No valid JWT token found');
|
|
252
|
+
return null;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.error('❌ [AUTH] Error during token retrieval:', error);
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Remove authentication token (logout)
|
|
261
|
+
*/
|
|
262
|
+
export const removeAuthToken = async () => {
|
|
263
|
+
try {
|
|
264
|
+
await AsyncStorage.removeItem('auth_token');
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error('Error removing auth token:', error);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Validate if user is properly authenticated
|
|
272
|
+
* @returns boolean indicating if user has valid authentication
|
|
273
|
+
*/
|
|
274
|
+
export const isAuthenticated = async () => {
|
|
275
|
+
try {
|
|
276
|
+
const token = await getAuthToken();
|
|
277
|
+
return token !== null && token.length > 50;
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.error('❌ [AUTH VALIDATION] Error checking authentication status:', error);
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Ensure authentication is available before making API calls
|
|
286
|
+
* @param apiName - Name of the API being called (for logging)
|
|
287
|
+
* @returns boolean indicating if authentication is available
|
|
288
|
+
*/
|
|
289
|
+
export const ensureAuthentication = async apiName => {
|
|
290
|
+
const isAuth = await isAuthenticated();
|
|
291
|
+
if (!isAuth) {
|
|
292
|
+
console.warn(`⚠️ [${apiName}] No valid authentication available - API call may return limited data`);
|
|
293
|
+
} else {
|
|
294
|
+
console.log(`✅ [${apiName}] Authentication validated for API call`);
|
|
295
|
+
}
|
|
296
|
+
return isAuth;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// NOTE: getEnochToken and saveEnochToken have been removed from SDK.
|
|
300
|
+
// SDK now uses a single simplified token. Enoch-specific token management
|
|
301
|
+
// should be handled by the consuming app if needed.
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Verify token with backend
|
|
305
|
+
* @returns Boolean indicating if token is valid
|
|
306
|
+
*/
|
|
307
|
+
export const verifyToken = async () => {
|
|
308
|
+
try {
|
|
309
|
+
const token = await getAuthToken();
|
|
310
|
+
if (!token) {
|
|
311
|
+
console.warn('🔒 [TOKEN VERIFY] No token available for verification');
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
console.log('🔒 [TOKEN VERIFY] Verifying token with backend...');
|
|
315
|
+
console.log('🔒 [TOKEN VERIFY] Token preview:', `${token.substring(0, 20)}...`);
|
|
316
|
+
const response = await fetch(`${API_BASE_URL}/api/auth/verify`, {
|
|
317
|
+
method: 'GET',
|
|
318
|
+
headers: getAuthHeaders(token)
|
|
319
|
+
});
|
|
320
|
+
console.log('🔒 [TOKEN VERIFY] Verification response status:', response.status);
|
|
321
|
+
if (response.ok) {
|
|
322
|
+
console.log('✅ [TOKEN VERIFY] Token is valid');
|
|
323
|
+
return true;
|
|
324
|
+
} else {
|
|
325
|
+
const errorText = await response.text();
|
|
326
|
+
console.warn('❌ [TOKEN VERIFY] Token verification failed:', response.status, errorText);
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.error('❌ [TOKEN VERIFY] Token verification error:', error);
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// NOTE: getUserProfile, createOrUpdateProfile, and updateUserOnboardedStatus
|
|
336
|
+
// have been removed from SDK - these are Enoch-specific functions.
|
|
337
|
+
// Consuming apps (like OnairosEvents) should call these APIs directly.
|
|
338
|
+
|
|
339
|
+
// NOTE: getEventTimer has been removed from SDK - it's Enoch-specific.
|
|
340
|
+
// Consuming apps (like OnairosEvents) should call /enoch/event/timer directly.
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Check if a user email has admin privileges
|
|
344
|
+
* @param email User email to check
|
|
345
|
+
* @returns True if user is an admin
|
|
346
|
+
*/
|
|
347
|
+
export const isAdminEmail = email => {
|
|
348
|
+
if (!email) {
|
|
349
|
+
console.log('🔒 [Admin Check] No email provided');
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
const adminEmails = ['nicholas.berry@onairos.uk', 'zion.darko@onairos.uk', 'admin@enoch.events', 'admin@onairos.uk'];
|
|
353
|
+
const isAdmin = adminEmails.includes(email.toLowerCase());
|
|
354
|
+
if (isAdmin) {
|
|
355
|
+
console.log('🔑 [Admin Check] Admin access granted for:', email);
|
|
356
|
+
} else {
|
|
357
|
+
console.log('🚫 [Admin Check] No admin access for:', email);
|
|
358
|
+
}
|
|
359
|
+
return isAdmin;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Get the current admin status from AsyncStorage
|
|
364
|
+
* This could be used for caching admin status between sessions
|
|
365
|
+
*/
|
|
366
|
+
export const getAdminStatus = async () => {
|
|
367
|
+
try {
|
|
368
|
+
const adminStatus = await AsyncStorage.getItem('user_admin_status');
|
|
369
|
+
return adminStatus === 'true';
|
|
370
|
+
} catch (error) {
|
|
371
|
+
console.error('Error getting admin status:', error);
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Save admin status to AsyncStorage
|
|
378
|
+
* @param isAdmin Whether the user is an admin
|
|
379
|
+
*/
|
|
380
|
+
export const saveAdminStatus = async isAdmin => {
|
|
381
|
+
try {
|
|
382
|
+
await AsyncStorage.setItem('user_admin_status', isAdmin.toString());
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error('Error saving admin status:', error);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Get stored Onairos username for API calls
|
|
390
|
+
* This is used for data connector APIs (Reddit, etc.) that need the username
|
|
391
|
+
* @returns Stored username or null if not found
|
|
392
|
+
*/
|
|
393
|
+
export const getOnairosUsername = async () => {
|
|
394
|
+
try {
|
|
395
|
+
return await AsyncStorage.getItem('onairos_username');
|
|
396
|
+
} catch (error) {
|
|
397
|
+
console.error('Error getting Onairos username:', error);
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Save Onairos username for API calls
|
|
404
|
+
* @param username Username to store
|
|
405
|
+
*/
|
|
406
|
+
export const saveOnairosUsername = async username => {
|
|
407
|
+
try {
|
|
408
|
+
await AsyncStorage.setItem('onairos_username', username);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
console.error('Error saving Onairos username:', error);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Send email verification code
|
|
416
|
+
* @param email Email address to send verification code to
|
|
417
|
+
* @returns Result with success status and optional message
|
|
418
|
+
*/
|
|
419
|
+
export const sendEmailVerificationCode = async email => {
|
|
420
|
+
const url = `${API_BASE_URL}/email/verification`;
|
|
421
|
+
console.log('📧 [EMAIL VERIFY] Sending verification code to:', email);
|
|
422
|
+
console.log('📧 [EMAIL VERIFY] URL:', url);
|
|
423
|
+
|
|
424
|
+
// Wait for SDK to finish initializing (handles race condition)
|
|
425
|
+
const sdkReady = await waitForSDKInit();
|
|
426
|
+
if (!sdkReady) {
|
|
427
|
+
return {
|
|
428
|
+
success: false,
|
|
429
|
+
message: 'SDK is still initializing. Please wait a moment and try again.'
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
let headers;
|
|
433
|
+
try {
|
|
434
|
+
var _headers$Authorizatio;
|
|
435
|
+
headers = getDeveloperAuthHeaders();
|
|
436
|
+
console.log('📧 [EMAIL VERIFY] Headers OK, key:', ((_headers$Authorizatio = headers.Authorization) === null || _headers$Authorizatio === void 0 ? void 0 : _headers$Authorizatio.substring(0, 20)) + '...');
|
|
437
|
+
} catch (headerError) {
|
|
438
|
+
console.error('❌ [EMAIL VERIFY] Failed to get auth headers:', headerError === null || headerError === void 0 ? void 0 : headerError.message);
|
|
439
|
+
return {
|
|
440
|
+
success: false,
|
|
441
|
+
message: 'SDK not properly initialized. Please restart the app and try again.'
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
const body = JSON.stringify({
|
|
445
|
+
email,
|
|
446
|
+
action: 'request'
|
|
447
|
+
});
|
|
448
|
+
const maxRetries = 3;
|
|
449
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
450
|
+
try {
|
|
451
|
+
console.log(`📧 [EMAIL VERIFY] Attempt ${attempt}/${maxRetries}...`);
|
|
452
|
+
const controller = new AbortController();
|
|
453
|
+
const timeoutId = setTimeout(() => controller.abort(), 15000);
|
|
454
|
+
const response = await fetch(url, {
|
|
455
|
+
method: 'POST',
|
|
456
|
+
headers,
|
|
457
|
+
body,
|
|
458
|
+
signal: controller.signal
|
|
459
|
+
});
|
|
460
|
+
clearTimeout(timeoutId);
|
|
461
|
+
console.log('📧 [EMAIL VERIFY] Response status:', response.status);
|
|
462
|
+
const data = await response.json();
|
|
463
|
+
if (response.ok && data.success) {
|
|
464
|
+
console.log('✅ [EMAIL VERIFY] Verification code sent successfully');
|
|
465
|
+
return {
|
|
466
|
+
success: true
|
|
467
|
+
};
|
|
468
|
+
} else {
|
|
469
|
+
console.log('❌ [EMAIL VERIFY] Server error:', data.error || data.message);
|
|
470
|
+
return {
|
|
471
|
+
success: false,
|
|
472
|
+
message: data.error || data.message || 'Failed to send verification code'
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
} catch (error) {
|
|
476
|
+
const isTimeout = (error === null || error === void 0 ? void 0 : error.name) === 'AbortError';
|
|
477
|
+
console.error(`❌ [EMAIL VERIFY] Attempt ${attempt} failed:`, isTimeout ? 'TIMEOUT' : error === null || error === void 0 ? void 0 : error.message);
|
|
478
|
+
if (attempt < maxRetries) {
|
|
479
|
+
const delay = 1000 * attempt;
|
|
480
|
+
console.log(`🔄 [EMAIL VERIFY] Retrying in ${delay}ms...`);
|
|
481
|
+
await new Promise(resolve => setTimeout(() => resolve(), delay));
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
console.error('❌ [EMAIL VERIFY] All retries exhausted:', error === null || error === void 0 ? void 0 : error.message);
|
|
485
|
+
return {
|
|
486
|
+
success: false,
|
|
487
|
+
message: 'Network error. Please check your connection and try again.'
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
success: false,
|
|
493
|
+
message: 'Network error. Please try again.'
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Confirm email verification code
|
|
499
|
+
* NOTE: This is generic SDK email verification - does NOT create EnochUser
|
|
500
|
+
* Consuming apps should call /enoch/users/register after this if needed
|
|
501
|
+
* @param email Email address that received the code
|
|
502
|
+
* @param code Verification code entered by user
|
|
503
|
+
* @returns Result with success status, optional token, and message
|
|
504
|
+
*/
|
|
505
|
+
export const confirmEmailVerificationCode = async (email, code) => {
|
|
506
|
+
console.log('🔍 [CODE VERIFY] Verifying code for:', email);
|
|
507
|
+
|
|
508
|
+
// Wait for SDK to finish initializing (handles race condition)
|
|
509
|
+
const sdkReady = await waitForSDKInit();
|
|
510
|
+
if (!sdkReady) {
|
|
511
|
+
return {
|
|
512
|
+
success: false,
|
|
513
|
+
message: 'SDK is still initializing. Please wait a moment and try again.'
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
let headers;
|
|
517
|
+
try {
|
|
518
|
+
headers = getDeveloperAuthHeaders();
|
|
519
|
+
console.log('🔍 [CODE VERIFY] Headers OK');
|
|
520
|
+
} catch (headerError) {
|
|
521
|
+
console.error('❌ [CODE VERIFY] Failed to get auth headers:', headerError === null || headerError === void 0 ? void 0 : headerError.message);
|
|
522
|
+
return {
|
|
523
|
+
success: false,
|
|
524
|
+
message: 'SDK not properly initialized. Please restart the app and try again.'
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const url = `${API_BASE_URL}/email/verification`;
|
|
528
|
+
const body = JSON.stringify({
|
|
529
|
+
email,
|
|
530
|
+
code,
|
|
531
|
+
action: 'verify'
|
|
532
|
+
});
|
|
533
|
+
const maxRetries = 3;
|
|
534
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
535
|
+
try {
|
|
536
|
+
console.log(`🔍 [CODE VERIFY] Attempt ${attempt}/${maxRetries}...`);
|
|
537
|
+
const controller = new AbortController();
|
|
538
|
+
const timeoutId = setTimeout(() => controller.abort(), 15000);
|
|
539
|
+
const response = await fetch(url, {
|
|
540
|
+
method: 'POST',
|
|
541
|
+
headers,
|
|
542
|
+
body,
|
|
543
|
+
signal: controller.signal
|
|
544
|
+
});
|
|
545
|
+
clearTimeout(timeoutId);
|
|
546
|
+
console.log('🔍 [CODE VERIFY] Response status:', response.status);
|
|
547
|
+
const data = await response.json();
|
|
548
|
+
console.log('🔍 [CODE VERIFY] Response data:', JSON.stringify(data));
|
|
549
|
+
const token = data.token || data.jwtToken;
|
|
550
|
+
if (response.ok && data.success && token) {
|
|
551
|
+
var _data$accountInfo;
|
|
552
|
+
console.log('✅ [CODE VERIFY] Email verification successful');
|
|
553
|
+
const isReturningUser = data.existingUser === true;
|
|
554
|
+
const isNewUser = !isReturningUser;
|
|
555
|
+
const existingUserData = ((_data$accountInfo = data.accountInfo) === null || _data$accountInfo === void 0 ? void 0 : _data$accountInfo.existingUserData) || data.existingUserData || null;
|
|
556
|
+
const flowType = data.flowType || (isReturningUser ? 'returning_user' : 'onboarding');
|
|
557
|
+
await storeJWT(token);
|
|
558
|
+
await AsyncStorage.setItem('user_email', email);
|
|
559
|
+
const username = data.userName || data.username || email.split('@')[0];
|
|
560
|
+
await AsyncStorage.setItem('onairos_username', username);
|
|
561
|
+
await AsyncStorage.setItem('onairos_user', 'true');
|
|
562
|
+
return {
|
|
563
|
+
success: true,
|
|
564
|
+
token,
|
|
565
|
+
username,
|
|
566
|
+
isNewUser,
|
|
567
|
+
flowType,
|
|
568
|
+
existingUserData,
|
|
569
|
+
enochInstructions: data.enochInstructions
|
|
570
|
+
};
|
|
571
|
+
} else {
|
|
572
|
+
console.log('❌ [CODE VERIFY] Server error:', data.error || data.message);
|
|
573
|
+
return {
|
|
574
|
+
success: false,
|
|
575
|
+
message: data.error || data.message || 'Invalid verification code'
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
} catch (error) {
|
|
579
|
+
const isTimeout = (error === null || error === void 0 ? void 0 : error.name) === 'AbortError';
|
|
580
|
+
console.error(`❌ [CODE VERIFY] Attempt ${attempt} failed:`, isTimeout ? 'TIMEOUT' : error === null || error === void 0 ? void 0 : error.message);
|
|
581
|
+
if (attempt < maxRetries) {
|
|
582
|
+
const delay = 1000 * attempt;
|
|
583
|
+
console.log(`🔄 [CODE VERIFY] Retrying in ${delay}ms...`);
|
|
584
|
+
await new Promise(resolve => setTimeout(() => resolve(), delay));
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
console.error('❌ [CODE VERIFY] All retries exhausted:', error === null || error === void 0 ? void 0 : error.message);
|
|
588
|
+
return {
|
|
589
|
+
success: false,
|
|
590
|
+
message: 'Verification failed. Please check your connection and try again.'
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return {
|
|
595
|
+
success: false,
|
|
596
|
+
message: 'Verification failed. Please try again.'
|
|
597
|
+
};
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// NOTE: checkEnochOnairosConnection has been removed from SDK - it's Enoch-specific.
|
|
601
|
+
// Consuming apps (like OnairosEvents) should call /enoch/user/onairos-connection-status directly.
|
|
602
|
+
//# sourceMappingURL=authService.js.map
|