Firebase Custom Claims doesn't propagate

前端 未结 2 445
渐次进展
渐次进展 2020-12-07 05:29

I\'m working in an Angular6 app with angularfire2. I\'m setting the roles as custom claims in user creation, but it doesn\'t seem to propagate.

When I\'m creating th

2条回答
  •  不思量自难忘°
    2020-12-07 05:47

    For me it simply worked taking the advice from one of the comments:

    // --------
    // Frontend
    // --------
    
    // Triggering the cloud function
    const url: string = 'url-to-your-cloud-function'
    await this.http.post(url, {}).toPromise();
    
    
    // After cloud function was run and custom claim was set -> refresh the id token
    // The 'currentUser' is a reference to the firebase user
    await this.authService.currentUser.getIdToken(true);
    
    // --------
    // Cloud Function - createSubscription
    // --------
    
    const createSubscription = () => {  
      await admin.auth().setCustomUserClaims(userId, {
        subscriber: true
      })
    }
    
    

提交回复
热议问题