MCPcopy Create free account
hub / github.com/firebase/codelab-friendlychat-web / authStateObserver

Function authStateObserver

web/src/index.js:231–260  ·  view source on GitHub ↗
(user)

Source from the content-addressed store, hash-verified

229
230 // Triggers when the auth state change for instance when the user signs-in or signs-out.
231 function authStateObserver(user) {
232 if (user) { // User is signed in!
233 // Get the signed-in user's profile pic and name.
234 var profilePicUrl = getProfilePicUrl();
235 var userName = getUserName();
236
237 // Set the user's profile pic and name.
238 userPicElement.style.backgroundImage = 'url(' + addSizeToGoogleProfilePic(profilePicUrl) + ')';
239 userNameElement.textContent = userName;
240
241 // Show user's profile and sign-out button.
242 userNameElement.removeAttribute('hidden');
243 userPicElement.removeAttribute('hidden');
244 signOutButtonElement.removeAttribute('hidden');
245
246 // Hide sign-in button.
247 signInButtonElement.setAttribute('hidden', 'true');
248
249 // We save the Firebase Messaging Device token and enable notifications.
250 saveMessagingDeviceToken();
251 } else { // User is signed out!
252 // Hide user's profile and sign-out button.
253 userNameElement.setAttribute('hidden', 'true');
254 userPicElement.setAttribute('hidden', 'true');
255 signOutButtonElement.setAttribute('hidden', 'true');
256
257 // Show sign-in button.
258 signInButtonElement.removeAttribute('hidden');
259 }
260 }
261
262 // Returns true if user is signed-in. Otherwise false and displays a message.
263 function checkSignedInWithMessage() {

Callers

nothing calls this directly

Calls 4

getProfilePicUrlFunction · 0.70
getUserNameFunction · 0.70
saveMessagingDeviceTokenFunction · 0.70

Tested by

no test coverage detected