【发布时间】:2018-06-11 06:46:13
【问题描述】:
我正在尝试在 firebase 的 google 函数中设置自定义声明。这是我的代码。
admin.auth().setCustomUserClaims(user.uid,{
activeNetworkProfile: networkProfile,
activeCompanyProfile: companyProfile,
activeUserProfile: profiles[0]
});
在客户端我有以下内容:
public updateProfiles(){
return this.afAuth.idToken.pipe(
switchMap(idToken => this.httpClient.post<any>('https://us-central1-company-database.cloudfunctions.net/updateProfiles',{
"token": idToken,
"np":"hzlNpVEdwqOKRTcsdfPG",
"cp":"D7nKYrS235A9vnvfB9oD"
}))
);
}
然后对已经进行的更改进行测试:
public validateToken(){
return this.afAuth.idToken.pipe(
switchMap(idToken => this.httpClient.post<any>('https://us-central1-company-database.cloudfunctions.net/validateToken',{
"token": idToken
}))
);
}
在服务器上我有以下内容:
export const validateToken = functions.https.onRequest((req, res) => {
return cors(req, res, () => {
const db = admin.firestore();
let token = req.body.token;
admin.auth().verifyIdToken(token).then(decodedToken=>{
res.status(200).send(decodedToken);
})
.catch(error=>{
res.status(401).send(error.message);
});
});
});
我没有收到回复中的声明。我尝试通过将参数设置为 true 来强制 angularfire2 中的更新
public getToken(){
return this.afAuth.auth.currentUser.getIdToken(true);
}
但这并没有改变任何东西,如果它导致 firebase 令牌更新进入无限循环。
【问题讨论】:
标签: angular firebase google-cloud-firestore angularfire2