Firebase Auth:如何使用 Laravel 在重定向页面中获取用户电话号码

我不知道我想要做的事情有多大可能,或者是否有更好的方法。我已经在我的系统中集成了 firebase 电话号码身份验证,它工作正常,但我想要它只是为了验证用户的电话号码,之后它会将用户重定向到主注册页面,用户将在其中输入将保存在的其他详细信息我的数据库。我正在使用在 div 中呈现 Ui 的 firebaseUi


<h1>Welcome to My Awesome App</h1>

<div id="firebaseui-auth-container"></div>

<div id="loader"></div>

我如何让经过验证的号码/当前用户显示在重定向页面上。我已经从管理用户文档中尝试过这个


var user = firebase.auth().currentUser;


if (user) {

  // User is signed in.

} else {

  // No user is signed in.

}

并在我的重定向页面中获取它,我的控制器中有这个


$this['authUser'] = Request::get('user');

然后在树枝上我有 {{ authUser }}但是当我拨号和转储时它返回空


慕的地6264312
浏览 171回答 1
1回答

子衿沉夜

嗯,这解决了它将此添加到js代码中<script type="text/javascript">&nbsp; &nbsp; &nbsp; initApp = function() {&nbsp; &nbsp; &nbsp; &nbsp; firebase.auth().onAuthStateChanged(function(user) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (user) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // User is signed in.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var displayName = user.displayName;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var email = user.email;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var emailVerified = user.emailVerified;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var photoURL = user.photoURL;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var uid = user.uid;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var phoneNumber = user.phoneNumber;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var providerData = user.providerData;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.getIdToken().then(function(accessToken) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('sign-in-status').textContent = 'Signed in';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('sign-in').textContent = 'Sign out';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('account-details').textContent = JSON.stringify({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayName: displayName,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; email: email,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; emailVerified: emailVerified,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phoneNumber: phoneNumber,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; photoURL: photoURL,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uid: uid,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accessToken: accessToken,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; providerData: providerData&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, null, '&nbsp; ');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // User is signed out.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('sign-in-status').textContent = 'Signed out';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('sign-in').textContent = 'Sign in';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('account-details').textContent = 'null';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }, function(error) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(error);&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; window.addEventListener('load', function() {&nbsp; &nbsp; &nbsp; &nbsp; initApp();&nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; </script>然后在页面<div&nbsp; id="sign-in-status"></div>&nbsp; &nbsp; <div&nbsp; id="sign-in"></div>&nbsp; &nbsp; <pre&nbsp; id="account-details"></pre>
打开App,查看更多内容
随时随地看视频慕课网APP