react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

[🐛]🔥 Storage emulator is not used when uploading to non-default bucket

Open BrianSladek opened this issue 1 year ago • 1 comments

Issue

When I upload to a non-default bucket, the file is unexpectedly uploaded to the live storage, not the emulator storage.

For example, this code uploads the file to the production storage:

    const storageRef = firebase
      .app()
      .storage("gs://my-second-bucket")
      .ref()
      .child("texts/file.txt");
    await storageRef.put(blob);

But, if I simply remove the bucket name, the file is uploaded to the default storage in the emulator:

    const storageRef = firebase
      .app()
      .storage()
      .ref()
      .child("texts/file.txt");
    await storageRef.put(blob);

Prior to this, I am instructing the app to use emulator storage like so:

import storage, { firebase } from "@react-native-firebase/storage";
storage().useEmulator("localhost", 8083);
firebase.app().storage().useEmulator("localhost", 8083); // don't think this line is needed, but tried it anyway
firebase.app().storage("gs://my-second-bucket").useEmulator("localhost", 8083); // don't think this line is needed, but tried it anyway

I have confirmed that the second bucket is set up in the emulator. I can view it and write to it from the emulator interface, so not sure why the code is choosing to upload to the live storage instead of using the emulator.


Project Files

Javascript

Click To Expand

package.json:

{
  "name": "mobile",
  "main": "expo-router/entry",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^14.0.0",
    "@react-native-async-storage/async-storage": "1.21.0",
    "@react-native-firebase/app": "^19.1.1",
    "@react-native-firebase/auth": "^19.1.1",
    "@react-native-firebase/firestore": "^19.1.1",
    "@react-native-firebase/functions": "^19.1.1",
    "@react-native-firebase/storage": "^19.1.1",
    "@react-native-google-signin/google-signin": "^10.1.1",
    "@react-navigation/native": "^6.0.2",
    "@rneui/base": "^4.0.0-rc.7",
    "@rneui/themed": "^4.0.0-rc.8",
    "expo": "^50.0.14",
    "expo-crypto": "~12.8.1",
    "expo-dev-client": "^3.3.0",
    "expo-document-picker": "~11.10.1",
    "expo-file-system": "~16.0.8",
    "expo-font": "~11.10.3",
    "expo-linking": "~6.2.2",
    "expo-router": "~3.4.8",
    "expo-splash-screen": "~0.26.4",
    "expo-sqlite": "~13.4.0",
    "expo-status-bar": "~1.11.1",
    "expo-system-ui": "~2.9.3",
    "expo-web-browser": "~12.8.2",
    "formik": "^2.4.5",
    "react": "^18.2.0",
    "react-dom": "18.2.0",
    "react-native": "^0.73.6",
    "react-native-gesture-handler": "~2.14.0",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0",
    "react-native-web": "~0.19.6",
    "react-native-webview": "13.6.4",
    "react-native-windows": "^0.73.11",
    "react-native-zip-archive": "^6.1.0",
    "yup": "^1.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.2.14",
    "jest": "^29.2.1",
    "jest-expo": "~50.0.4",
    "react-test-renderer": "18.2.0",
    "typescript": "^5.1.3"
  },
  "overrides": {
    "react-refresh": "~0.14.0"
  },
  "resolutions": {
    "react-refresh": "~0.14.0"
  },
  "private": true,
  "packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}

firebase.json for react-native-firebase v6:

{
  "functions": [
    {
      "source": "functions/teamA",
      "codebase": "team-a",
      "ignore": [
        "venv",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    },
    {
      "source": "functions/teamB",
      "codebase": "team-b",
      "ignore": [
        "venv",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    }
  ],
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "emulators": {
    "functions": {
      "port": 5003
    },
    "firestore": {
      "port": 8082
    },
    "storage": {
      "port": 8083
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true,
    "auth": {
      "port": 9099
    }
  },
  "storage": [
    {
      "target": "default",
      "rules": "storage.rules"
    },
    {
      "target": "texts",
      "rules": "storage.texts.rules"
    }
  ]
}

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A

Android

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:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment

Click To Expand

react-native info output:

System:
  OS: macOS 14.1
  CPU: (14) arm64 Apple M3 Max
  Memory: 225.34 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.7.1
    path: ~/.nvm/versions/node/v21.7.1/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v21.7.1/bin/npm
  Watchman:
    version: 2024.03.25.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2021.1 AI-211.7628.21.2111.8092744
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: ^18.2.0
  react-native:
    installed: 0.73.6
    wanted: ^0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
  • Platform that you're experiencing the issue on:
    • [x ] iOS
    • [ ] Android
    • [ ] 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:
    • 19.1.1
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y, 5.1.3

BrianSladek avatar Mar 31 '24 14:03 BrianSladek

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.

github-actions[bot] avatar Apr 28 '24 15:04 github-actions[bot]