invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.64k stars 2.21k forks source link

[🐛] [🔥] sendPasswordResetEmail - auth/internal-error when url included #6838

Closed mbaker3 closed 8 months ago

mbaker3 commented 1 year ago

Issue

Currently having issues sending a password reset email when the continue URL is included. When a whitelisted URL is included in the actionCodeSettings object firebase returns an auth/internal-error. I haven't yet tried setting up dynamic links to see if the continue URL will work with a dynamic link vs a standard (whitelisted) url.

I'm hoping to be able to redirect to one of our own web pages once password reset is complete. I don't believe setting up dynamic links should be required but feel free to dismiss this bug if I've misinterpreted what firebase should support!

(This is in an Expo project using the custom dev client)

My usage is as follows

import auth, { FirebaseAuthTypes } from "@react-native-firebase/auth";
import * as Application from "expo-application";
// ...
auth()
   .sendPasswordResetEmail(email, {
      url: "https://my.whitelisted.url.com",
      handleCodeInApp: false,
      iOS: { bundleId: Application.applicationId! },
      android: {
        packageName: Application.applicationId!,
       installApp: true,
      },
    })
   .then(()=>console.log("success"))
   .catch((error) => console.error(error))

The error emitted: [auth/internal-error] An internal error has occurred, please try again.


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "scripts": { "start": "npx expo start --dev-client", "prebuild-ios": "npx expo prebuild -p ios --clean", "local-build-ios": "eas build --platform ios --local --profile debug-simulator", "remote-build-debug-sim": "eas build --platform ios --profile debug-simulator", "remote-build-debug": "eas build --platform ios --profile debug", "remote-build-stage": "eas build --platform ios --profile stage", "remote-build-beta": "eas build --platform ios --profile beta", "publish-debug": "eas update --branch debug --message", "publish-stage": "expo publish --release-channel stage", "publish-beta": "expo publish --release-channel beta", "android": "npx expo run:android", "ios": "npx expo run:ios" }, "dependencies": { "@logrocket/react-native": "^1.5.0", "@react-native-async-storage/async-storage": "~1.17.3", "@react-native-firebase/app": "^16.4.3", "@react-native-firebase/auth": "^16.4.3", "@react-native-firebase/crashlytics": "^16.4.3", "@react-native-firebase/firestore": "^16.4.3", "@react-native-firebase/functions": "^16.4.3", "@react-native-firebase/perf": "^16.4.3", "@react-native-google-signin/google-signin": "8.0.0", "@react-navigation/bottom-tabs": "^6.3.3", "@react-navigation/native": "^6.0.12", "@react-navigation/stack": "^6.2.3", "@types/lodash": "^4.14.185", "dayjs": "^1.11.5", "expo": "~46.0.19", "expo-app-loading": "~2.1.0", "expo-apple-authentication": "~4.3.0", "expo-build-properties": "~0.3.0", "expo-clipboard": "~3.1.0", "expo-dev-client": "~1.3.1", "expo-device": "~4.3.0", "expo-font": "~10.2.0", "expo-linking": "~3.2.4", "expo-splash-screen": "~0.16.2", "expo-status-bar": "~1.4.0", "expo-updates": "~0.14.7", "react": "18.0.0", "react-dom": "18.0.0", "react-native": "0.69.6", "react-native-date-picker": "^4.2.5", "react-native-gesture-handler": "~2.5.0", "react-native-reanimated": "~2.9.1", "react-native-safe-area-context": "4.3.1", "react-native-screens": "~3.15.0", "react-native-svg": "12.3.0", "react-native-uuid": "^2.0.1", "react-native-web": "~0.18.7", "system-ui": "^1.0.0" }, "devDependencies": { "@babel/core": "^7.18.6", "@babel/plugin-proposal-logical-assignment-operators": "^7.18.9", "@types/react": "~18.0.0", "@types/react-native": "~0.69.1", "@typescript-eslint/eslint-plugin": "^5.38.0", "@typescript-eslint/parser": "^5.38.0", "eslint": "^8.23.1", "eslint-config-universe": "^11.1.0", "eslint-plugin-react-hooks": "^4.6.0", "prettier": "^2.7.1", "react-native-svg-transformer": "^1.0.0", "typescript": "^4.6.3" }, "resolutions": { "@logrocket/react-native/@expo/config-plugins": "^5.0.0" }, "eslintConfig": { "extends": [ "universe/native", "plugin:react-hooks/recommended" ], "rules": { "object-shorthand": "off", "react/jsx-boolean-value": "off" } }, "private": true, "name": "some-app", "version": "1.0.0" } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking") require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods") require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), "native_modules") require 'json' podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {} platform :ios, podfile_properties['ios.deploymentTarget'] || '12.4' install! 'cocoapods', :deterministic_uuids => false target 'SomeApp' do use_expo_modules! config = use_native_modules! use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config[:reactNativePath], :hermes_enabled => flags[:hermes_enabled] || podfile_properties['expo.jsEngine'] == 'hermes', :fabric_enabled => flags[:fabric_enabled], # An absolute path to your application root. :app_path => "#{Dir.pwd}/.." ) # Uncomment to opt-in to using Flipper # Note that if you have use_frameworks! enabled, Flipper will not work # # if !ENV['CI'] # use_flipper!() # end post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) # This is necessary for Xcode 14, because it signs resource bundles by default # when building for devices. installer.target_installation_results.pod_target_installation_results .each do |pod_name, target_installation_result| target_installation_result.resource_bundle_targets.each do |resource_bundle_target| resource_bundle_target.build_configurations.each do |config| config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' end end end end post_integrate do |installer| begin expo_patch_react_imports!(installer) rescue => e Pod::UI.warn e end end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" // AUTO GENERATED START - DO NOT EDIT: Auto generated at build time by: withLocalNotification #import #import "LocalNotification.h" // AUTO GENRATED END - withLocalNotification #import #import #import #import #import #import #import #if RCT_NEW_ARCH_ENABLED #import #import #import #import #import #import #import static NSString *const kRNConcurrentRoot = @"concurrentRoot"; @interface AppDelegate () { RCTTurboModuleManager *_turboModuleManager; RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; std::shared_ptr _reactNativeConfig; facebook::react::ContextContainer::Shared _contextContainer; } @end #endif @implementation AppDelegate // AUTO GENERATED START - DO NOT EDIT: Auto generated at build time by: withLocalNotification { UserNotificationDelegate *_notificationDelegate; } // AUTO GENRATED END - withLocalNotification - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // AUTO GENERATED START - DO NOT EDIT: Auto generated at build time by: withLocalNotification _notificationDelegate = [[UserNotificationDelegate alloc] init]; [UNUserNotificationCenter currentNotificationCenter].delegate = _notificationDelegate; // AUTO GENRATED END - withLocalNotification RCTAppSetupPrepareApp(application); // @generated begin @react-native-firebase/app-didFinishLaunchingWithOptions - expo prebuild (DO NOT MODIFY) sync-ecd111c37e49fdd1ed6354203cd6b1e2a38cccda [FIRApp configure]; // @generated end @react-native-firebase/app-didFinishLaunchingWithOptions RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions]; #if RCT_NEW_ARCH_ENABLED _contextContainer = std::make_shared(); _reactNativeConfig = std::make_shared(); _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer]; bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; #endif NSDictionary *initProps = [self prepareInitialProps]; UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:initProps]; rootView.backgroundColor = [UIColor whiteColor]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [self.reactDelegate createRootViewController]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; [super application:application didFinishLaunchingWithOptions:launchOptions]; return YES; } - (NSArray> *)extraModulesForBridge:(RCTBridge *)bridge { // If you'd like to export some custom RCTBridgeModules, add them here! return @[]; } /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. /// /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). /// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`. - (BOOL)concurrentRootEnabled { // Switch this bool to turn on and off the concurrent root return true; } - (NSDictionary *)prepareInitialProps { NSMutableDictionary *initProps = [NSMutableDictionary new]; #if RCT_NEW_ARCH_ENABLED initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); #endif return initProps; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } // Linking API - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options]; } // Universal Links - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result; } // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { return [super application:application didFailToRegisterForRemoteNotificationsWithError:error]; } // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } #if RCT_NEW_ARCH_ENABLED #pragma mark - RCTCxxBridgeDelegate - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge { _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self jsInvoker:bridge.jsCallInvoker]; return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager); } #pragma mark RCTTurboModuleManagerDelegate - (Class)getModuleClassFromName:(const char *)name { return RCTCoreModulesClassProvider(name); } - (std::shared_ptr)getTurboModule:(const std::string &)name jsInvoker:(std::shared_ptr)jsInvoker { return nullptr; } - (std::shared_ptr)getTurboModule:(const std::string &)name initParams: (const facebook::react::ObjCTurboModule::InitParams &)params { return nullptr; } - (id)getModuleInstanceFromClass:(Class)moduleClass { return RCTAppSetupDefaultModuleFromClass(moduleClass); } #endif @end ```


Android

Not currently targeting with app.

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` info Fetching system and libraries information... System: OS: macOS 13.1 CPU: (10) arm64 Apple M1 Pro Memory: 170.20 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.0 - /var/folders/bh/46mx29x52bd3lxp94d1l0w1m0000gn/T/yarn--1673930127780-0.9800396747328977/node Yarn: 1.22.19 - /var/folders/bh/46mx29x52bd3lxp94d1l0w1m0000gn/T/yarn--1673930127780-0.9800396747328977/yarn npm: 8.19.1 - /usr/local/bin/npm Watchman: 2022.07.04.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 31 Build Tools: 31.0.0, 32.0.0 System Images: android-25 | Google APIs ARM EABI v7a, android-31 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8309675 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: Not Found npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.6 => 0.69.6 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found info React Native v0.71.0 is now available (your project is running on v0.69.6). info Changelog: https://github.com/facebook/react-native/releases/tag/v0.71.0. info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.69.6. info To upgrade, run "react-native upgrade". ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [x] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `16.4.3` - `16.5.0` - **`Firebase` module(s) you're using that has the issue:** - `auth` - **Are you using `TypeScript`?** - `Y` & `4.8.3` - Expo verssion: - `46.0.19`


BohdanKasian commented 1 year ago

i have the same error, i use RN CLI(without Expo)

ShaneZhengNZ commented 1 year ago

Save issue. This is kind of annoying. Not sure whether this is a Firebase issue or this library's issue.

ShaneZhengNZ commented 1 year ago

I can replicate the issue with simple await auth().sendPasswordResetEmail(emailAddress);

mbaker3 commented 1 year ago

I can replicate the issue with simple await auth().sendPasswordResetEmail(emailAddress);

I haven't had this issue specifically. When sending just an email address, the request succeeds and I do get an email on the other end. For me, including the continueURL is what breaks the request.

github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 1 year ago

This issue still requires attention.

Nik9687 commented 1 year ago

This issue still requires attention.

+1 here, i have the same issue wen when i add the continueURL

robnewton commented 1 year ago

+1 here too. Same issue when I add the url option and once or twice even when I don't add it. I wondered if it is related to a rate limit from calling it multiple times in a row during testing, but I waited a few hours and it's still an issue.

github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 1 year ago

This issue still requires attention.

robnewton commented 1 year ago

Also here still need attention

warloff commented 1 year ago

This still requires attention and better documentation on the use of sendPasswordResetEmail

github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 1 year ago

This issue still requires attention.

github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 1 year ago

This issue still requires attention.

vbarda commented 1 year ago

+1, also running into the same issue when including URL

github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 1 year ago

This issue still requires attention.

github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 1 year ago

This issue still requires attention.

github-actions[bot] commented 11 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

mbaker3 commented 11 months ago

This issue still requires attention. It's worked its way far enough up my backlog that I'll probably investigate the source myself in the next few months.

mrtawil commented 11 months ago

Hello @mbaker3, did you try enabling dynamic links in Firebase project?

mbaker3 commented 11 months ago

I haven't, as far as I understand it shouldn't be required if the URL is whitelisted. I had planned to test out Dynamic Links but I'm a bit hesitant to invest the effort since it's being deprecated in the future anyway. I'll see what I can do when I jump back on this bug in a couple of months.

opsb commented 11 months ago

Same problem with the dart api, including a url with a whitelisted domain throw an internal error exception.

mrtawil commented 11 months ago

Hello @mbaker3, did you try enabling dynamic links in Firebase project?

I am using the following code:

user.sendEmailVerification({
  handleCodeInApp: true,
  url: `https://${Config.APP_SHARE_HOST}?mode=verifyEmail`,
});

On Android the email was sent successfully without any issues, and here is the result:

image

While on iOS it was failing, I have read in another thread that enabling dynamic links in Firebase console will fix this and it did in my case. As you can see in the following link, the URL is generated from dynamic links in iOS case:

image
mbaker3 commented 11 months ago

Hmmm, interesting. Requiring DynamicLinks makes sense in your case because you're asking to handle the flow in your app with handleCodeInApp: true.

We want to rely on the web flow to handle our reset so we have handleCodeInApp: false. However looking at the docs on the parameters again I noticed that it's expecting a Universal link for the url param...

This URL represents the state/Continue URL in the form of a universal link. This URL can should be constructed as a universal link that would either directly open the app where the action code would be handled or continue to the app after the action code is handled by Firebase.

I'm not sure how I missed that on first pass but it seems a regular URL was never expected to work?!

If that's the case then this my original report on this issue is not a bug. Leaving this issue open until I verify that constructing a universal link does in fact work.

github-actions[bot] commented 10 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

opsb commented 10 months ago

This appears to be a documentation issue. Support got back to me and told me that you have to use dynamic links, it won't work without them currently.

mikehardy commented 10 months ago

I did not know that! Very interesting given dynamic-links is deprecated+sunsetting but I suppose if it's a requirement now it's a requirement. If there is any place in our documentation on rnfirebase.io that you notice related to this which would be improved by noting the dynamic-links as a strict requirement, there's an edit button top right of every page (even the types pages built off typescript - they are turned into the docs site dynamically after merging an edit)

github-actions[bot] commented 9 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.