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

Moving between different perspectives within a single-page backbone application

I am interested in incorporating dynamic transitions similar to the ones showcased on this website into a single-page backbone application. However, I am unsure of where to begin. Do I need to modify how I initialize my views (currently using a standard sw ...

Using a HTML tag within vue js

Is it possible to dynamically change a <p> tag inside my component to be an <h1> tag based on a prop? If so, how can this be achieved? <template> <p>Hello world</p> </template> ...

What are some effective methods for incorporating large JSON data into a node.js script?

What is the best way to import a large JSON file (550MB) into a node.js script? I attempted: var json = require('./huge-data-set.json') The script was run with an increased --max-old-space-size parameter node --max-old-space-size=4096 diff.js ...

Arranging HTML components in Vue.js using v-for loop

Recently, I started using vue.js and I have a requirement where I need to display an HTML structure based on API data. The structure should look like this: <div class="row"> <div><p>text1</p><img src="{{imgurl1}}" /></di ...

The request to retrieve data from the model at http://localhost:9000/model/data.json resulted in a 404

This is the path to my directory I have a npm server running on http://localhost:9000/ to utilize the cytoscape module. However, my server is unable to locate my json file. What could be the issue with my code? This is the source code of my index.js file ...

Is there a way to determine the names of the functions that are being called?

I'm working on mastering Google Development Tools. Is there a way to determine which specific functions, especially those in Javascript, are needed before a page can load successfully? ...

Express JS encountering Firebase Google Sign-In glitch

Whenever a user clicks a button on the HTML page, this function is triggered. The function resides in auth.js and it is called from the server.js page. auth.js const firebase = require("firebase"); static googleSignIn(req,res){ firebase.aut ...

Transforming a file with a node module that lacks a .js class into a browseable format

I am currently working on browserifying my module. One of the dependencies I have is on this https://www.npmjs.com/package/chilkat_win32. It is present in my node_modules folder and here is how the structure looks: https://i.stack.imgur.com/uw9Pg.png Upo ...

Leveraging Scrapy/Selenium for populating fields and conducting searches on LinkedIn's advanced search page

Discover the URL for LinkedIn's advanced search feature: In my attempt to complete fields and submit a form on the LinkedIn advanced search page using Selenium with Python, I encountered a challenge. Whenever I try typing in information for fields l ...

I must pause for a specified period before initializing the subsequent component in React Native

Due to restrictions on my API key, I can only make one request every 5 seconds. Therefore, I need to wait for 5 seconds before making another request for NearbyJobs (with the first request being made for PopularJobs). <ScrollView showsVerticalScrollIndi ...

Issues with Props being undefined when used in a Vue.js component method

I recently started incorporating Vue.js into a Django project that is structured as a multi-page application. My initial task involves creating a basic logout component that will make a POST request to the logout route. The endpoint for this route is obta ...

Testing abstract class methods in Jest can ensure full coverage

In my project, I have an abstract generic service class. export default abstract class GenericService<Type> implements CrudService<Type> { private readonly modifiedUrl: URL; public constructor(url: string) { this.modifiedUrl = ...

Encountering an issue with html2canvas: receiving an error message stating "object

To print the div using Javascript, I encountered an issue with the generated barcode not appearing in the printed page. This led me to use the html2canvas approach to 'render' the div before printing it out. Here is the code snippet: HTML: < ...

Fix a typing issue with TypeScript on a coding assistant

I'm struggling with typing a helper function. I need to replace null values in an object with empty strings while preserving the key-value relationships in typescript // from { name: string | undefined url: string | null | undefined icon: ...

The initial click may not gather all the information, but the subsequent click will capture all necessary data

Issue with button logging on second click instead of first, skipping object iteration function. I attempted using promises and async await on functions to solve this issue, but without success. // Button Code const btn = document.querySelector("button") ...

Delay the HTTPs request until the password encryption is complete

Hey there! I'm working on a post request where I need to collect login data (name, email, password) from users, validate it, encrypt the password, and then store the data. However, I'm facing an issue with the encryption function taking time to r ...

What is the best way to create a dynamic hyperlink that leads to a detailed information page based on the specific link clicked?

I'm currently working on a web page that displays a list of users, and I want each user's name to be clickable, leading to a page with specific details about that user. I'm new to this field, so I'm unsure where to start. My idea is to ...

Synchronizing client information in real-time: tips, tricks, and expert advice

Currently, I am developing a PHP backend and utilizing JS/Jquery for the front end of an application that aims to facilitate near real-time communication among users. My main concern right now is determining the most effective approach to achieve this goal ...

The comparison between local variables and data can result in a significant drop in performance

My current project involves VueJS and Cesium, but I'm facing a performance issue with a significant drop in frame rate. While I have identified the problem area, I am unsure of why this is happening and how to resolve it. export default { name: ...

Javascript and CSS combo for creating a stylish fade effect

Hey everyone, I have a design challenge where I need to change the color of a picture inside a box when the user hovers over it. I have four boxes like this and my goal is to make everything else fade out when a user hovers over a specific box. Anyone kn ...