Reputation: 1
Ok, so I have a website with a forum that is using firebase to hold the data for the forum posts and the user data to login. The problem I am having is pulling data from the users child when they log on so that the forum can use that data. When the user creates their account, they create a username along with email and password. What I want to do is display that username in the forum whenever they add a post, but whatever I try just doesn't seem to be pulling the username from firebase. When the user logs in, I want the data to be sent from my login controller to a service.js file so that all my separate controllers and html pages can see the username data and display what I need.
Upvotes: 0
Views: 199
Reputation: 1058
It sounds like you are using angular...I think?
If so, you can save the returned login data to the $rootScope, or even better use localstorage. Then just access it from one of those when needed.
// Create a callback to handle the result of the authentication
function authHandler(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
$rootScope.user = authData.uid;
}
}
// Authenticate users with a custom Firebase token
ref.authWithCustomToken("<token>", authHandler);
// Alternatively, authenticate users anonymously
ref.authAnonymously(authHandler);
// Or with an email/password combination
ref.authWithPassword({
email : '[email protected]',
password : 'correcthorsebatterystaple'
}, authHandler);
Upvotes: 1