Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda