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

240
Views
Firebase: ¿por qué no se agrega el reclamo a los atributos del usuario?

Estoy agregando el reclamo al perfil de un usuario de que él o ella pagó por algo, sin embargo, después del pago, este atributo no es visible. Estoy ejecutando las funciones en un emulador en un host local.

Este es el código que estoy usando:

Si la función de paypal se ha manejado con éxito a través de paypalHandleOrder, entonces se invoca la función addPaidClaim.

 onApprove: (data, actions) => { paypalHandleOrder({ orderId: data.orderID }).then( addPaidClaim(currentUser).then( alert("THANKS FOR ORDERING!"), // currentUser.getIdTokenResult().then(idTokenResult => { // console.log(idTokenResult.claims) // }) ) .catch((err) => { return err; }) );}

addPaidClaim es una función en la nube de firebase, que es la siguiente:

 exports.addPaidClaim = functions.https.onCall((data, context) => { // get user and add custom claim (paid) return admin.auth().setCustomUserClaims(data.uid, { paid: true, }).then(() => { return { message: `Success! ${data.email} has paid the course`, }; }).catch((err) => { return err; }); });

Actualicé la página y luego verifiqué los atributos del usuario a través de console.log en el usuario para ver si se había agregado el atributo, pero este no es el caso. No puedo encontrar el atributo pagado dentro del objeto idTokenResult. ¿Qué tengo que hacer? También me resulta difícil dar sentido a lo que sucede dentro de la función addPaidClaim. No devuelve un error cuando miro los registros en mi consola Firebase, y no se proporciona mucha información, además de que se invocó la función.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Bien, sé que esta pregunta es bastante antigua. Pero encontré una manera ayer después de 3 días buscando la solución. Después de configurar un nuevo reclamo para un nuevo usuario, debemos actualizar el getIdTokenResult(true) del cliente en la aplicación. Estas son las formas en que lo hice en Flutter Dart hasta que un nuevo usuario con un reclamo actualizado logró usarlo:

 FirebaseAuth auth = FirebaseAuth.instance; Future<Map<String, dynamic>> signInWithGoogle() async { Map<String, dynamic> output = {}; final googleUser = await googleSignIn.signIn(); if (googleUser == null) { log("Firebase => Gmail account doesn't exist"); } else { final googleAuth = await googleUser.authentication; final credential = GoogleAuthProvider.credential( idToken: googleAuth.idToken, accessToken: googleAuth.accessToken, ); await auth.signInWithCredential(credential).then((values) async { await userAuth(credential).then((value) => value.addAll(output)); }); } return output; } Future<Map<String, dynamic> userAuth (OAuthCredential credential) async { Map<String, dynamic> output = {}; await auth.currentUser!.reauthenticateWithCredential(credential); await auth.currentUser!.reload(); await auth.currentUser!.getIdTokenResult().then((result) => { if(result.claims!.isNotEmpty){ //check your claim here } else { //assign log here } }); return output; }

about 4 years ago · Juan Pablo Isaza Report
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!