Search⌘ K

Your First Chat Message

Explore how to prompt users for their names and save chat messages to Cloud Firestore in this lesson. Learn to use JavaScript with localStorage to manage user identities and store messages in a database collection. Understand how to set up input forms, handle events, and view stored messages in the Firebase console, providing the foundation for a real-time chat application.

Who is chatting

In order to have an effective chat application, we need a way to tie each message to the person who is sending it. To do that we will ask each user for their name.

Prompt for Name

This is some JavaScript logic that prompt a user for their name. This simulates an authentication experience without actually authenticating the user. Full user authentication using Firebase is covered in a later section of the course.

With JavaScript, we check to see if the key of name is in localStorage. If there is not a name then we ask for it with the browsers built-in prompt. Then, after we have the name supplied by the user ...