Is it possible to retrieve any user data by id using Vue 3 Firebase Auth?

I'm a newcomer to vue/firebase and I've been able to easily access the "current user" data from authentication. However, I am struggling to write a JavaScript composable that can retrieve the user object or at least displayName when passing in any user id (not just the current user).

All the resources I've come across only cover obtaining information on the *current user*, rather than another user. According to the Google Docs, this should be possible in the "Retrieve user data" section. The code structure similar to Vue appears to be “Node.Js” but I haven't had any success with it.

This is what I have for the getUserById function:

import { getAuth } from 'firebase/auth'

const getUserById = (userId) => {
    const userData = null
    getAuth()
        .getUser(userId)
        .then((userRecord) => {
            // See the UserRecord reference doc for the contents of userRecord.
            console.log(`Successfully fetched user data: ${userRecord.toJSON()}`);
            userData = userRecord
        })
        .catch((error) => {
            console.log('Error fetching user data:', error);
        });

    return { userData }
}
export default getUserById

The error message I receive is "getUser is not a function." I attempted adding getUser to the import statement, but encountered the same error.

Answer №1

Searching for user information by their unique identifier (UID) using Firebase's client-side APIs is not possible due to security reasons. However, the Admin SDK does provide an API for retrieving user data based on UID, but this should only be done in a secure environment like a server or Cloud Functions/Cloud Run, and not in client-side code.

If you require this feature in your application, one option is to create a custom secured endpoint that utilizes the functionality from the Admin SDK. Alternatively, users can store their information in a cloud database (such as Realtime Database or Firestore) and access it from there.

For more information, check out these resources:

  • How to get FirebaseUser from a uid?
  • Firebase get user by ID
  • Is there any way to get Firebase Auth User UID?

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

Sustaining authentication in React using Firebase

I successfully integrated firebase authentication for email login and registration into my React app. Now, I'm looking to enhance it with a "remember me" checkbox feature. Although I have experience with the onAuthStateChanged listener and understand ...

A guide on sending events to a different component that is not a direct parent in vue.js

Within the example below, the initial component imports various other components and then displays them in the template. Among these imported components are a Stages component and a StageExecutionTimes component. My goal is to enable the hiding of the Stag ...

JavaScript's toFixed method for decimals

I am encountering an issue with displaying prices for my products. I have labels in the form of "span" elements with prices such as 0.9, 1.23, and 9.0. I am using the method "toFixed(2)" to round these prices to two decimal places. However, I have notice ...

Stop the execution of jQuery ready handlers

I am facing a situation where I need to prevent jQuery ready handlers from firing on the DOMContentReady event under certain conditions. These handlers are set up in different places like include files, plugins, and more. While one approach could involve s ...

Is there a way to have content update automatically?

After writing this block of code, I discovered that clicking on one of the circles activates it and displays the corresponding content. Now, I am looking for a way to automate this process so that every 5 seconds, a new circle gets activated along with its ...

The image will come to life with animation as the background position is adjusted using Skrollr

Trying to create a div that switches the background image every X pixels scrolled. Initially experimented with changing the background-image, including using sprites and adjusting background position, but encountered a distracting "flickering" effect. Exa ...

The error event in events.js on line 72 was not properly handled, causing an exception to be thrown

When attempting to utilize the node-ar-drone package to control an AR Parrot Drone 2 and interface with it, I encounter errors after connecting to the drone's wireless network on my OSX Yosemite: 587214779:examples mona$ node png-stream.js Connectin ...

How can I access and retrieve information from a text file that is saved in Firebase storage using React?

I currently have text files saved in Firebase storage, with their download URLs stored in my Firestore database. However, I am facing difficulty in accessing and utilizing the data within these text files from Firebase storage. Issue: My goal is to direct ...

The www file is only loaded by Node Inspector when the preload setting is turned off

Whenever I start node-inspector The node-inspector browser window successfully loads all the files. However, when I use node-inspector --preload=false Only my bin/www file is loaded on the node-inspector window. Oddly enough, my colleagues are not f ...

The React render function fails to display the components it is supposed to render

Upon running npm start, the browser opens localhost:3000 but only displays a white page. To troubleshoot, I added a paragraph within the <body> tag in index.html. Surprisingly, the text Hello World! appeared for less than a second before disappearing ...

Handling overflow and z-index of tabs in Vuetify Drawer

Struggling to create an expandable sidebar menu using Vuetify2, following the documentation, but unable to prevent the expanded menu from overlapping other elements on the page. The current behavior causes items to be pushed away and wrap onto the next ro ...

The HTML body content of an iframe

Hey there, I'm trying to get just the body html from an iframe using my code. Currently it returns all the html of the iframe. Does anyone have any ideas on how to modify this? Here's the code snippet: alert( $("#uploaderIframe").contents()[0]. ...

Is there a way to place my searchbox in the top right corner of the page?

I am currently working on creating a search function for my list of products. However, I have encountered an issue where the searchBox is not appearing in the top right corner as intended. Despite trying various solutions, I have been unsuccessful in movin ...

Issue with Vue.js v-show functionality not triggering properly following an axios request

I am facing an issue where v-show is not behaving as expected. I suspect this is because this.conversation.hidden is not initially set when the browser is rendered due to it being loaded asynchronously. How can I resolve this issue? Thank you in advance! ...

Ensure that the textbox remains safe from accidental keyboard inputs

How can I ensure that users can only select a date from the calendar control in my textbox, rather than typing it manually, even if I make the textbox read-only? ...

Retrieving all selected checkboxes in AngularJS

I am a beginner in angular js and here is my template: <div class="inputField"> <h1>Categories</h1> <div> <label><input type="checkbox" id="all" ng-model="all" ng-change="checkAll();" ng-true-value="1">A ...

Customizing the Material UI theme colors using Typescript

I have created my own unique theme and now I am attempting to assign one of the custom colors I defined to a button. However, when I try to set it as: color={theme.pallete.lightGrey} I run into this error message: No overload matches this call Overload 1 ...

Submitting an image from React and Redux to the backend: A comprehensive guide

I'm currently working with the MERN stack and facing an issue while trying to upload an image in the front end (react) and then access it in the backend (express, nodejs) for later storage. Despite using multer, I keep encountering 'undefined&apo ...

Remove all of the classes from the specified element using JavaScript

I have a button and I want to remove all the classes when it is clicked. Here is what I have tried: button.style.className = '' document.querySelector('button').onclick = function() { this.style.className = ''; } .myClas ...

Implement an AJAX link on the webpage using Yii framework

I'm currently working on developing a user interface for an application, and I've encountered an issue with my code that involves adding AJAX links using a Yii helper function. echo CHtml::ajaxLink('Link', array('getajaxlinks&apos ...