[英]Firebase+Javascript Convert anonymous account to permanent - Error: response is not defined
I'm trying to build a site where the user can first login anonymously using firebase and then convert his account to permanent by signing in with facebook. 我正在尝试建立一个站点,用户可以首先使用firebase匿名登录,然后通过使用Facebook登录将其帐户转换为永久帐户。 I'm following the instructions given at https://firebase.google.com/docs/auth/web/anonymous-auth but i'm getting the following error "Uncaught ReferenceError: response is not defined". 我正在按照https://firebase.google.com/docs/auth/web/anonymous-auth上给出的说明进行操作,但出现以下错误“ Uncaught ReferenceError:未定义响应”。 I also tried converting the account using Google Sign in but then i get the error "googleUser is not defined". 我也尝试使用Google登录来转换帐户,但随后出现错误“未定义googleUser”。 What am i doing wrong? 我究竟做错了什么?
This is my code:- 这是我的代码:
<html>
<body>
<button onclick = "anonymousLogin()">Anonymous Signin</butto>
<button onclick = "facebookSignin()">Facebook Signin</button>
<button onclick = "facebookSignout()">Facebook Signout</button>
</body>
<script>
function anonymousLogin(){
firebase.auth().signInAnonymously().catch(function(error) {
// Handle Errors here.
var errorCode = error.code; console.log(errorCode)
var errorMessage = error.message; console.log(errorMessage)
});
}
function facebookSignin() {
var provider = new firebase.auth.FacebookAuthProvider();
var credential = firebase.auth.FacebookAuthProvider.credential(
response.authResponse.accessToken);
auth.currentUser.link(credential).then(function(user) {
console.log("Anonymous account successfully upgraded", user);
}, function(error) {
console.log("Error upgrading anonymous account", error);
});
}
</script>
</html>
okay i found a solution. 好吧,我找到了解决方案。 Apparently converting from anonymous to facebook user needs you to find the token yourself. 从匿名用户转换为Facebook用户显然需要您自己找到令牌。 I found this workaround. 我找到了解决方法。
var provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().currentUser.linkWithPopup(provider)
I think response
here refers to the event that Facebook login passes to the callback. 我认为此处的response
是指Facebook登录信息传递给回调的事件。 Facebook traditionally calls this response
, but our Github sample calls it events
. Facebook传统上将这种response
称为events
,但我们的Github示例将其称为events
。 The name of course isn't important, but you're not declaring it for your callback. 名称当然并不重要,但是您并未在回调中声明它。
function facebookSignin(response) {
var provider = new firebase.auth.FacebookAuthProvider();
var credential = firebase.auth.FacebookAuthProvider.credential(
response.authResponse.accessToken);
Also see https://github.com/firebase/quickstart-js/blob/master/auth/facebook-credentials.html#L81 另请参阅https://github.com/firebase/quickstart-js/blob/master/auth/facebook-credentials.html#L81
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.