steps for signing up and keeping the parameters current

I am currently working on an app using React Native built with Expo.

I have been trying to register and update some columns, but I am encountering issues.

Below is a snippet of my source code:

import * as Location from 'expo-location';
const URL = {
    CREATE_CURRENT_LOCATION:'https://sayhellotobike-native-ios-default-rtdb.firebaseio.com'
}

export const requestLocationPermission = async (setLocationCallBack,myCurrentLocationArray,setIsMapReady) => {
try {
    const { status } = await Location.requestForegroundPermissionsAsync();
    if (status === 'granted') {
        // Execute the process to get current location
        getCurrentLocation(setLocationCallBack,myCurrentLocationArray,setIsMapReady);
        
    } else {
        console.log('Location permission denied');
    }
    } catch (error) {
        console.error('Error requesting location permission:', error);
    }
};

export const getCurrentLocation = async (setLocationCallBack,myCurrentLocationArray,setIsMapReady) => {
    try {
        const { coords } = await Location.getCurrentPositionAsync({});
        const { latitude, longitude } = coords;
        setLocationCallBack({ ...myCurrentLocationArray,latitude, longitude });
        setIsMapReady(true); 
        writeMyLocationData(URL.CREATE_CURRENT_LOCATION,0,latitude,longitude)
        } catch (error) {
            console.error('Error getting current location:', error);
        } 
};

import { ref, set } from "firebase/database";
import { database } from '../firebaseConfig'; 
export const writeMyLocationData = async (url, userId, latitude, longitude) => {
  console.log("Writing data:", url, userId, latitude, longitude);
  let params = {
      user_id: userId,
      latitude: latitude,
      longitude: longitude[enter image description here](https://i.sstatic.net/3GnaeJSl.png)
    }
  try{
    set(ref(database, url + 'location'), params
  )
  }catch(error){
    console.error(error)
  }finally{
    console.log("Process sent.")
  }
  console.log("fetchLocation",fetchLocation)
}

I suspect that there might be an issue with the path due to special characters.

The error code states:

Error: child failed: path argument was an invalid path = "https:your text//sayhellotobike-native-ios-default-rtdb.firebaseio.com/location/latitude". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"

I have tried changing the path to:

/location 
/location/latitude 
location
/

And various other options.

import { initializeApp } from 'firebase/app';
import { getAuth } from "firebase/auth"
import { getDatabase }from "firebase/database";

const firebaseConfig = {
  apiKey: "AIzaSyCe2ZqMbYldfc-M7hXEBBSNJHnJy5gMig4",
  authDomain: "sayhellotobike-native-ios.firebaseapp.com",
  databaseURL: "https://sayhellotobike-native-ios-default-rtdb.firebaseio.com",
  projectId: "sayhellotobike-native-ios",
  storageBucket: "sayhellotobike-native-ios.appspot.com",
  messagingSenderId: "94237205998",
  appId: "1:94237205998:web:879feeef3ddb781d3e1aff",
  measurementId: "G-ZLR4NQ9XG4"
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const database = getDatabase(app);

Answer №1

It seems like the issue you're facing stems from using ref(db, path) from the firebase/database package instead of refFromURL(db, url).

The error occurs because you mistakenly input a URL into the ref function when it actually requires a path.

ref(database, url + 'location')

This error is triggered by the restriction on the path variable that disallows certain characters like periods (".") in the domain:

Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"

To utilize a URL, it's recommended to use refFromURL instead.

refFromURL(database, url + 'location');

However, considering the value of URL.CREATE_CURRENT_LOCATION, you may need to adjust either url + '/location' or

new URL('location', url).toString()
to ensure the URL is constructed correctly. Presently, the generated URL would be
"https://<db>.firebaseio.comlocation"
instead of
"https://<db>.firebaseio.com/location"
.

refFromURL(database, url + '/location');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Node.js in Phonegap

Currently, I am in the process of creating an iOS application with PhoneGap and I have an interest in incorporating node.js into a specific aspect of it. Is it possible to integrate an instance of node.js within the app using PhoneGap? ...

The onChange method seems to be malfunctioning when used with radio buttons

I'm having an issue with my form's radio button. It is supposed to do something when the selected item changes, but it only works when the page first loads and not when I select a different item. Below is the code snippet: <div key={item} cla ...

Learning to control the JavaScript countdown clock pause and play functionality

How can I control the countdown timer to play and pause, allowing me to resume at the exact time it was paused? At the start, the timer is set to play. Please keep in mind that the button appears empty because the font-awesome package was not imported, b ...

Enable Intellisense for my custom ES6 JavaScript modules in VS Code

Using VS Code Intellisense can greatly enhance productivity when working with internal project files, providing helpful autocompletion features and utilizing written JSDoc comments. However, my current projects involve custom JavaScript libraries stored i ...

When using Next.js and Express.js together, CORS error may occur, causing API queries to only function properly during build

I am currently working on a project that involves using Next.js for the front-end and Express.js for the back-end. Front-end Setup The 'pages' directory contains an 'index.js' file where I have implemented the following code snippet: ...

Hacking through external script injections into the browser

Curious about how certain software or programs are able to inject html,css,js into a web browser without the need for installing any extensions. Every time I open Chrome or Firefox, I'm bombarded with ads on popular sites like Google homepage, Faceboo ...

Ascending with Progress Indicator Slider

After successfully creating a Bootstrap 5 Carousel with an automated count for each slide (limited to 4) and a corresponding progress bar, I encountered an issue with getting the previous button to function correctly. While clicking the next button works s ...

Utilizing a window.onload function in Microsoft Edge

After trying to run some code post-loading and rendering on the target page, I was recommended to use the Window.load function. This method worked flawlessly in Firefox and Chrome, but unfortunately, I couldn't get it to function in IE. Is there an al ...

CSRF fails to execute during the initial post submission

This is my first time dealing with CSRF and reaching out to Stack Overflow for the first time. After struggling through the configuration, I finally managed to get it working almost perfectly. However, I ran into an issue where if I open a bookmarked page ...

Gulp and Vinyl-fs not functioning properly when trying to save in the same folder as the source file due to issues with

After exploring a variety of solutions, I have yet to find success in modifying a file in place using Gulp.js with a globbing pattern. The specific issue I am facing can be found here. This is the code snippet I am currently working with: var fstrm = re ...

Encountering an issue while invoking the helper function in Vuejs

Main view: <script> import { testMethod1 } from "../helper"; export default { methods: { init(){ console.log("Res:", testMethod1()); } } } </script> Helper: import DataService from "../services/data. ...

Guide on retrieving a nested JSON array to extract a comprehensive list of values from every parameter within every object

A JSON file with various data points is available: { "success": true, "dataPoints": [{ "count_id": 4, "avg_temperature": 2817, "startTime": "00:00:00", "endTime": "00:19:59.999" }, ... I am trying to extract all the values of & ...

Change the display of the lightbox when clicked. Utilize Angular and JQuery for this functionality

Here is the code for a lightbox: <div id="light-box"> <div id="first"> ..... </div> //initially visible <div id="second"> ..... </div> //hidden - but displayed when button is clicked. </div> I want to add two button ...

Automatically unselect the "initially selected item" once two items have been selected in Material UI

As someone new to web development, I'm struggling with a specific task. Here is the issue at hand: I have three checkboxes. If box1 and then box2 are selected, they should be marked. However, if box3 is then selected, box1 should automatically unchec ...

What is the process for "dereferencing" an object?

How can you access the properties of an object returned by a function in JavaScript? For instance: var tmp = getTextProperties(); font = tmp.font; size = tmp.size; color = tmp.color; bold = tmp.bold; italic = tmp.italic; While PHP offers the list ...

Cross-site communication with Ajax using both POST and GET requests

As a beginner in JavaScript, I'm facing challenges with implementing ajax POST and GET requests. While I can successfully do it using Google Postman as shown here https://i.sstatic.net/Cegxj.pnghttps://i.sstatic.net/ovJT0.png, the problem arises when ...

React Native - Similar components scrolling in unison

Currently utilizing NativeBase alongside React Native. This is the method I am using to create tabs with NativeBase: <Tabs> <Tab heading="Tab1"> <Tab1 /> </Tab> <Tab heading="Tab2"> <Tab2 /> </Tab> ...

Is it possible to reduce a field value in firestore after successfully submitting a form?

I have a variety of items retrieved from firestore: availability : true stocks: 100 item: item1 https://i.stack.imgur.com/hrfDu.png I am interested in reducing the stocks after submitting a form. I used the where() method to check if the selected item m ...

Type parameter in express.js route

If I have this specific route in my Express.js server: router.get('/ad/:id', (req, res) => { const { id } = req.params Ad.getAd(id, (err, resp) => { if(err){ return handleError('Failed to load an ad' ...

What is causing such a delay in this AJAX request?

It typically takes around 2-4 seconds to complete, which seems excessive for its task. Below is the AJAX code: $("#IngTable").html("<center><img src=../img/loading.gif /></center>"); var search = document.getElementById("IngSearch") ...