Angular Firebase身份验证部队在signin中更新声明

Angular Firebase身份验证部队在signin中更新声明,angular,typescript,firebase,firebase-authentication,ngrx-effects,Angular,Typescript,Firebase,Firebase Authentication,Ngrx Effects,在我的应用程序中,注册新用户时,我需要确保在导航到路由之前,它在调用getIdTokenResult(true)方法时,在claims中获得我需要的值 我正在将forceRefresh参数传递为true,但我无法更新customClaims,我需要注销用户并登录以获取更新的数据 我需要确保,每当用户注册时,他都会在设置状态并导航到主屏幕之前等待返回带有更新声明的令牌 private _setUserControlAccess = firebase.functions() .httpsCa

在我的应用程序中,注册新用户时,我需要确保在导航到路由之前,它在调用
getIdTokenResult(true)
方法时,在
claims
中获得我需要的值

我正在将
forceRefresh
参数传递为true,但我无法更新customClaims,我需要注销用户并登录以获取更新的数据

我需要确保,每当用户注册时,他都会在设置状态并导航到主屏幕之前等待返回带有更新声明的令牌

private _setUserControlAccess = firebase.functions()
    .httpsCallable('setUserControlAccess')

@Effect()
signin$: Observable<Action> = this._actions.pipe(
    ofType(authActions.SIGNIN),
    map((action: authActions.Signin) => action.payload),
    switchMap(user => {

        this._matSnackbar.open('Efetuando o registro...', '', {
            horizontalPosition: this._horizontalPosition,
            verticalPosition: this._verticalPosition,
        });

        return from(this._angularFireAuth.auth
            .createUserAndRetrieveDataWithEmailAndPassword(user.email, user.password)).pipe(
                switchMap(response => this._setUserConfigurations(response, user)),
                //filter() Add filter here? to check token.claims.firestoreCollection exists?
                map(([_, token, user]) => {
                    const authStateObject = this._getAuthStateObject(token, user);

                    // before setting the state, I need to ensure that token.claims is updated.
                    return new authActions.Authenticated(authStateObject);
                }),
                tap(() => this._router.navigate([''])),
                catchError((error) => of(new authActions.AuthError({ error: error })))
            )
    })
)


private _setUserConfigurations(
    response: firebase.auth.UserCredential,
    user: any
) {
    return forkJoin([
        from(response.user.updateProfile({
            displayName: user.nome.trim(),
            photoURL: 'assets/images/avatars/profile.jpg'
        })),
        from(response.user.getIdTokenResult(true)),
        from(of(response.user)),
        from(this._setUserControlAccess({
            firestoreCollection: response.user.uid,
            admin: true,
            assinante: true,
            profissional: true,
            email: response.user.email
        }))
    ]);
}

private _getAuthStateObject(
    token: firebase.auth.IdTokenResult,
    user: firebase.User
) {
    const authStateObject = {
        admin: token.claims.admin,
        profissional: token.claims.profissional,
        assinante: token.claims.assinante,
        firestoreCollection: token.claims.firestoreCollection,
        user: user
    }

    return authStateObject;
}
export const setUserControlAccess = functions.https.onCall(async (data, context) => {
    try {
        const customUserClaims = {
            admin: data.admin,
            assinante: data.assinante,
            profissional: data.profissional,
            firestoreCollection: data.firestoreCollection
        };

        const user = await admin.auth().getUserByEmail(data.email);
        await authentication.setCustomUserClaims(user.uid, customUserClaims);

    } catch (error) {
        console.error(error);
        return error;
    }
});