Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda