Custom Usernames with Firebase Authentication
Key Takeaways
This video demonstrates how to add custom usernames to Firebase users and validate them asynchronously using Angular 4, with Firebase Authentication and AngularFire2.
Full Transcript
in this episode we're going to create custom usernames for Firebase users then validate the usernames asynchronously using angular 4 users will first authenticate with ooth then they'll be directed to a username form and after each key press the username will be updated based on whether or not it's available in the database the first step is to model the data first we have a user's collection that saves just basic information about the user that we want to display throughout the app then we have a separate collection of just usernames where the username itself is the key and the value is the associated user ID this allows us to make checks for username availability much more quickly than we could if we query the entire list of [Music] users now we can start building the off service we're going to import the angular Fire 2 package both the database and the off module we also import the RX xjs switch map operator which we'll use to avoid nested subscriptions when we get the user data I'm also creating a dedicated user class to hold the user data in this case it's just going to take a username and a user ID and as the Constructor it'll take the Firebase off object in the service Constructor we first wait for the O object to emit from Firebase and then we use that data to query the database for the actual username the first function is going to allow the user to authenticate with their Google account this codes directly from the angular Fire 2 package to manage the username process we start by creating a getter to see if a username is defined or not then we create a check username function which will check the username collection to see if that particular username is defined lastly we create a function for the user to select their username this updates both the usern name's document as well as the user specific user document under their user ID now we can start building the component we start by injecting the off service then we set one variable for the username text which is what the user enters into the form then we set a separate variable for username available which is a Boolean true or false whether or not the username is available first the user will sign in with Google which will populate their user ID and then we'll display the form to fill out the username the check username function will send the actual request to the database to see if the username is available the return value is converted to a Boolean then we set that to our username available variable then we'll create an event handler to update the database when the user selects a valid username in the template we start with the sign in with Google button then once we have a current user and if their username is undefined then we display the username form the input itself uses NG model to set the username text variable and the component typescript then we bind the key up event to the check username function now we can display a couple messages conditionally based on whether or not that username is available we can also use the username available Boolean to disable the button if that username is already taken [Music] so now we have a working username system and we can see that it updates the database at both locations when the user clicks the button [Music] our final step is to enforce this validation on the back end with Firebase database rules we do this by setting a validation Rule and traversing the database calling root child usernames and then seeing if the new data the user is trying to enter already exists in the database if it does the rule will evaluate to false and prevent the operation from taking place [Music] that's it for this episode if you found the video helpful please like And subscribe and if you want to support the channel consider becoming a pro subscriber at angular firebase.com for just a few bucks a month you'll get access to exclusive content as well as free one-on-one project Consulting thanks for watching and I'll see you next time audio jump
Original Description
Full lesson: https://angularfirebase.com/lessons/custom-usernames-with-firebase-authentication-and-angular/
Learn how to add custom usernames to Firebase users, then asynchronously validate them with Angular 4.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Fireship · Fireship · 16 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
▶
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Angular 4 Development and Production Environments with Firebase
Fireship
OAuth with Angular and Firebase Tutorial
Fireship
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
Angular Router Guards for Firebase Users
Fireship
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
Upload Files from Angular to Firebase Storage
Fireship
How to Deploy an Angular App to Firebase Hosting
Fireship
Sharing Data between Components in Angular
Fireship
Loading Spinners for Asynchronous Firebase Data
Fireship
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
Firebase Database Rules Tutorial
Fireship
Autocomplete Search with Angular4 and Firebase
Fireship
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
Custom Usernames with Firebase Authentication
Fireship
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
Simple Pagination with Firebase and Angular 4
Fireship
How to Connect Firebase Users to their Data - 3 Methods
Fireship
Add Toast Message Notifications to your Angular App
Fireship
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
Learn NgModule in Angular with Examples
Fireship
Lazy Loading Components in Angular 4
Fireship
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
Angular 4 Full Text Search with Algolia - Part 1
Fireship
Algolia with Firebase Cloud Functions - Part 2
Fireship
Firebase Phone Authentication in Angular 4
Fireship
Top 7 RxJS Concepts for Angular Developers
Fireship
Learn Angular Animations with 5 Examples
Fireship
Advanced Firebase Data Filtering (Multi-Property)
Fireship
Realtime Maps with Mapbox + Firebase + Angular
Fireship
Angular Reactive Forms with Firebase Database Backend
Fireship
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
Top 7 Ways to Debug Angular 4 Apps
Fireship
Infinite Scroll with Angular and Firebase
Fireship
Use TypeScript with Firebase Cloud Functions
Fireship
Realtime Graphs and Charts with Plotly and Firebase
Fireship
Role-Based User Permissions in Firebase
Fireship
User Presence System in Realtime - Online, Offline, Away
Fireship
Location-based Queries with GeoFire and Angular Google Maps
Fireship
Angular ngrx Redux Quick Start Tutorial
Fireship
Angular Ngrx Effects with Firebase Database
Fireship
Progressive Web Apps with Angular
Fireship
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
RxJS Quick Start with Practical Examples
Fireship
Send SMS Text Messages with Twilio and Firebase
Fireship
Firebase Database Performance Profiling
Fireship
Native Desktop Apps with Angular and Electron
Fireship
Subscription Payments with Stripe, Angular, and Firebase
Fireship
Firestore with AngularFire5 Quick Start Tutorial
Fireship
Angular HTTP Client Quick Start Tutorial
Fireship
Google Sign-In with Firestore Custom User Data
Fireship
Star Review System from Scratch with Firestore + Angular
Fireship
Angular Chatbot with Dialogflow (API.ai)
Fireship
Learn @ngrx/entity and Feature Modules
Fireship
Infinite Scroll Pagination with Firestore
Fireship
Faster Firestore via Data Aggregation
Fireship
Contentful - CMS for Angular Progressive Web Apps
Fireship
More on: AI Pair Programming
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Common Next.js Errors (and How I Solved Them)
Dev.to · gary killen
Applying Scalability in Backend (CodeBuddy)
Medium · LLM
Why Every Backend Developer Should Learn Nginx Before Going to Production
Medium · DevOps
Connecting Frontend to Backend: A Backend Engineer’s Reality Check
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI