MCPcopy Create free account
hub / github.com/firebase/quickstart-js / newPostForCurrentUser

Function newPostForCurrentUser

database/scripts/main.ts:566–586  ·  view source on GitHub ↗

* Creates a new post for the current user.

(title: string, text: string)

Source from the content-addressed store, hash-verified

564 * Creates a new post for the current user.
565 */
566function newPostForCurrentUser(title: string, text: string) {
567 const userId = auth.currentUser!.uid;
568
569 return new Promise((resolve) => {
570 onValue(
571 ref(database, '/users/' + userId),
572 function (snapshot) {
573 const username =
574 (snapshot.val() && snapshot.val().username) || 'Anonymous';
575 return writeNewPost(
576 auth.currentUser!.uid,
577 username,
578 auth.currentUser!.photoURL,
579 title,
580 text,
581 ).then(resolve);
582 },
583 { onlyOnce: true },
584 );
585 });
586}
587
588/**
589 * Displays the given section element and changes styling of the given button.

Callers 1

main.tsFile · 0.85

Calls 1

writeNewPostFunction · 0.85

Tested by

no test coverage detected