Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Unique username validation angular fire

I'm currently working on a register form with angular fire. I want to create a custom validation that search through users collection and return true if displayName already exist.

My code looks like this

username: new UntypedFormControl('', [
            Validators.required,
            Validators.minLength(6),
            Validators.maxLength(12),
            this.checkUsername(this.firestore),
        ])


checkUsername(firestore: AngularFirestore) {
        return (control: AbstractControl) => {
            const displayName = control.value

            return firestore
                .collection('users', (ref) => ref.where('displayName', '==', displayName))
                .snapshotChanges()
                .subscribe((docs) => {
                    // loop through each item in the array and log value
                    docs.map((doc) => {
                        return doc.payload.doc.exists ? { usernameUnavailable: true } : null
                    })
                })
        }
    }

even if doc.payload.doc.exist returns true, there is no custom error added to the form field. Am i missing something?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!