如何在OAuth之后使用Meteor v1.4+;中的内置帐户ui包填充客户端Meteor.user.services;?
我在Meteor v1.4.1中使用帐户ui和帐户google。我无法使如何在OAuth之后使用Meteor v1.4+;中的内置帐户ui包填充客户端Meteor.user.services;?,meteor,meteor-accounts,Meteor,Meteor Accounts,我在Meteor v1.4.1中使用帐户ui和帐户google。我无法使user.services对象在客户端代码中显示范围。特别是,我需要谷歌的个人资料图片 我已将服务器端代码配置为通过Google身份验证,如下所示: import { Meteor } from 'meteor/meteor'; import { ServiceConfiguration } from 'meteor/service-configuration'; const services = Meteor.setti
user.services
对象在客户端代码中显示范围。特别是,我需要谷歌的个人资料图片
我已将服务器端代码配置为通过Google身份验证,如下所示:
import { Meteor } from 'meteor/meteor';
import { ServiceConfiguration } from 'meteor/service-configuration';
const services = Meteor.settings.private.oauth;
for (let service of Object.keys(services)) {
ServiceConfiguration.configurations.upsert({
service
}, {
$set: {
clientId: services[service].app_id,
secret: services[service].secret,
loginStyle: "popup"
}
});
}
…和客户端代码来配置权限,如下所示:
Accounts.ui.config({
requestPermissions: {
google: ['email', 'profile']
},
forceApprovalPrompt: {
google: true
},
passwordSignupFields: 'EMAIL_ONLY'
});
当用户单击“使用谷歌登录”按钮时,会出现一个弹出窗口,用户可以进行身份验证。但是,尽管google
的forceApprovalPrompt
设置为true,但不会出现提示
最大的问题是当我执行这个
const user = Meteor.user();
console.log(user.services);
在客户端代码的任何地方,我都看不到预期的用户服务信息。我检查了我的数据库,它肯定是在那里拍摄的:
$ mongo localhost:27017
> db.users.find({})
> ... "services" : { "google" : { "accessToken" : ... } } ...
我很好奇我错过了什么?为了让用户服务数据存在于客户端中,我是否应该明确定义发布函数?出于安全原因,服务属性被故意隐藏在客户端。这里有两种方法: 建议
//服务器
流星法({
getProfilePicture(){
const services=Meteor.user().services;
//替换为实际配置文件图片属性
return services.google&&services.google.profilePicture;
}
});
//客户
Meteor.call('getProfilePicture',(呃,profilePicture)=>{
console.log('profile picture url',profilePicture);
});
//配置用户创建时配置文件数据的情况
Accounts.onCreateUser((选项,用户)=>{
如果(!('profile'在选项中)){options.profile={};}
如果(!('providers'在options.profile中)){options.profile.providers={};}
//在此处定义其他特定配置文件选项
if(user.services.google){
options.profile.providers.google={
图片:user.services.google.picture
}
}
user.profile=options.profile;
返回用户;
});
//服务器
Meteor.publish('userData',函数(){
if(this.userId){
返回Meteor.users.find({u id:this.userId}{
字段:{other:1,things:1}
});
}否则{
这个;
}
});
//客户
Meteor.subscribe('userData');