使用Facebook登录后如何询问额外信息?
How to ask extra information after login with facebook?
我已经设置了基本的 meteor 应用程序,我可以在其中使用 facebook 登录。在实际创建用户之前,我想请求一个有效的 phone 号码。你如何在流星中做到这一点?
登录工作流程:
登录页面 => 点击 'login with facebook' => 用户授予应用权限 => 重定向回应用并请求 phone 号码 => 创建用户
我正在使用 accounts-facebook 和相关包。
谢谢
由于FacebookAPIdoesn't support access to the user phone, you can't just extend the requestPermission数组,求user_phone.
假设您有这个简单的“使用 Facebook 登录”按钮
Meteor.loginWithFacebook({ requestPermissions: ['email']},
function (error) {
if (error) {
return console.log("There was an error : " error.reason);
}else{
//if there is no error, lets redirect the new user to a new template
Router.go('/registerForm')
}
});
现在,如果登录成功,您可以将用户重定向到 registerForm
。
注册表单HTML
<template name="registerForm">
<!-- Simple Register Form asking for phone number -->
</template>
JS 事件
Template.registerForm.events({
'submit registerForm':function(e,t){
//code to get the input value
var userPhoneNumber = t.$('#phoneInputValue').val()
Meteor.users.update(Meteor.userId(),{$set:{'profile.phoneNumber':userPhoneNumber,'profileNumber':true}})
}
})
您看到布尔值 profileNumber
了吗?有了这个,你可以使用模板助手来确保和拒绝访问用户,如果他不填写 registerForm
模板(只是一个额外的安全),你可以在服务器端使用 Accounts.onCreateUser
默认设置它像这样的方法。
Accounts.onCreateUser(function(options, user) {
if(!options || !user) {
console.log('error creating user');
return;
} else {
if(options.profile) {
user.profile.userPhoneNumber = false;
}
}
return user;
});
我已经设置了基本的 meteor 应用程序,我可以在其中使用 facebook 登录。在实际创建用户之前,我想请求一个有效的 phone 号码。你如何在流星中做到这一点? 登录工作流程:
登录页面 => 点击 'login with facebook' => 用户授予应用权限 => 重定向回应用并请求 phone 号码 => 创建用户
我正在使用 accounts-facebook 和相关包。
谢谢
由于FacebookAPIdoesn't support access to the user phone, you can't just extend the requestPermission数组,求user_phone.
假设您有这个简单的“使用 Facebook 登录”按钮
Meteor.loginWithFacebook({ requestPermissions: ['email']},
function (error) {
if (error) {
return console.log("There was an error : " error.reason);
}else{
//if there is no error, lets redirect the new user to a new template
Router.go('/registerForm')
}
});
现在,如果登录成功,您可以将用户重定向到 registerForm
。
注册表单HTML
<template name="registerForm">
<!-- Simple Register Form asking for phone number -->
</template>
JS 事件
Template.registerForm.events({
'submit registerForm':function(e,t){
//code to get the input value
var userPhoneNumber = t.$('#phoneInputValue').val()
Meteor.users.update(Meteor.userId(),{$set:{'profile.phoneNumber':userPhoneNumber,'profileNumber':true}})
}
})
您看到布尔值 profileNumber
了吗?有了这个,你可以使用模板助手来确保和拒绝访问用户,如果他不填写 registerForm
模板(只是一个额外的安全),你可以在服务器端使用 Accounts.onCreateUser
默认设置它像这样的方法。
Accounts.onCreateUser(function(options, user) {
if(!options || !user) {
console.log('error creating user');
return;
} else {
if(options.profile) {
user.profile.userPhoneNumber = false;
}
}
return user;
});