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.