如果您对reactjs–放置firebase.auth()的位置.onAuthStateChanged()和reactajax放在哪里感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解reactj
如果您对reactjs – 放置firebase.auth()的位置.onAuthStateChanged()和react ajax放在哪里感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解reactjs – 放置firebase.auth()的位置.onAuthStateChanged()的各种细节,并对react ajax放在哪里进行深入的分析,此外还有关于@react-native-firebase/auth 不适用于 ios、angular – Firebase – 如何检测/观察Firebase用户何时验证其电子邮件,如onAuthStateChanged、angularjs – Firebase $authWithOAuthRedirect在没有页面刷新的情况下不会调用$onAuth、angularjs – 来自Facebook的$authWithOAuthRedirect之后,Firebase $onAuth的authData错误的实用技巧。
本文目录一览:- reactjs – 放置firebase.auth()的位置.onAuthStateChanged()(react ajax放在哪里)
- @react-native-firebase/auth 不适用于 ios
- angular – Firebase – 如何检测/观察Firebase用户何时验证其电子邮件,如onAuthStateChanged
- angularjs – Firebase $authWithOAuthRedirect在没有页面刷新的情况下不会调用$onAuth
- angularjs – 来自Facebook的$authWithOAuthRedirect之后,Firebase $onAuth的authData错误
reactjs – 放置firebase.auth()的位置.onAuthStateChanged()(react ajax放在哪里)
我根据 this link上发现的react-router示例创建了受保护的路由,到目前为止一切正常.
现在,我从我的auth reducer获取用户身份验证时设置的用户的loggedIn状态,但我希望在页面刷新后使用onAuthStateChanged()保持loggedIn状态.
我应该在哪里放置onAuthStateChanged()函数?有没有最好的做法来使用它?
我的代码供以下参考:
App.js
<PrivateRoute path="/dashboard" component={Dashboard} /> <Route path="/login" component={Login} />
ProtectedRoute.js
const PrivateRoute = ({ component: Component,...rest }) => { const { loggedIn } = rest; return ( <Route {...rest} render={props => ( loggedIn ? (<Component {...props} />) : ( <Redirect to={{ pathname: '/login',state: { from: props.location } }} /> ) )} /> ) } function mapStatetoProps({auth}){ return { loggedIn: auth.loggedIn } } export default connect(mapStatetoProps)(PrivateRoute);
actions_auth.js
export const loginUser = ({ email,password },callback ) => { console.log(email,password) return(dispatch) => { dispatch({ type: LOGIN_USER }); auth.signInWithEmailAndPassword(email,password) .then( user => { dispatch({ type: LOGIN_USER_SUCCESS,payload: user }); callback(); },error => { console.log( error.message ); dispatch({ type: LOGIN_USER_FAIL,error: error.message }); } ) } }
reducer_auth.js
const INITIAL_STATE = { email: '',password: '',error: '',loading: false,loggedIn: false }; export default (state = INITIAL_STATE,action) => { switch (action.type) { case EMAIL_CHANGED: return { ...state,email: action.payload }; case PASSWORD_CHANGED: return { ...state,password: action.payload }; case LOGIN_USER: return { ...state,loading: true,error: '' }; case LOGIN_USER_SUCCESS: return { ...state,...INITIAL_STATE,user: action.payload,loggedIn: true }; case LOGIN_USER_FAIL: return { ...state,error: action.error }; case logoUT_USER: return { ...state,...INITIAL_STATE }; default: return state; } };
您可以查看 here以获取更多详细信息.
如果你经常使用firebase,我建议花一些时间来设置这个很棒的库 react-redux-firebase
@react-native-firebase/auth 不适用于 ios
如何解决@react-native-firebase/auth 不适用于 ios?
大家好,我正在尝试在我的应用程序中使用 react-native firebase phone auth
,但是当我尝试使用 SignInWithPhone
方法时,它遇到了一个错误,我不知道是怎么回事
谁能帮我解决这个问题!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
angular – Firebase – 如何检测/观察Firebase用户何时验证其电子邮件,如onAuthStateChanged
firebase.auth().onAuthStateChanged((user) => { console.log(user["emailVerified"]); })
不过我的问题是,只要用户在收件箱中验证了他们的电子邮件地址,我就会观察/收听并重定向到另一个页面.
根据我的测试,当用户登录,更新其个人资料并注销时会触发onAuthStateChanged,但在用户在其收件箱中验证其电子邮件地址时不会触发.
无论如何我可以检测到用户何时被验证并自动重定向到另一个页面?
解决方法
setInterval(function() { firebase.auth().currentUser.reload(); if (firebase.auth().currentUser.emailVerified) { console.log("Email Verified!"); this.navCtrl.setRoot(HomePage); } },1000);
angularjs – Firebase $authWithOAuthRedirect在没有页面刷新的情况下不会调用$onAuth
问题是,一旦我点击登录与Facebook按钮,我被重定向到Facebook,我登录,然后我被重定向回我的应用程序.但问题是我留在登录页面.奇怪的是,如果我通过按F5来物理刷新我的浏览器(使用离子服务测试)onAuth触发器,我将被重定向到Items页面.如果我不刷新浏览器,则不会调用onAuth.
有人有这个问题吗?你是怎么解决的?
请注意,是的,我做了我的研究(并且稍微开始失去它),但无法让它发挥作用.我搜索了SO,尝试使用google群组的$timeout,试图调用$scope.$apply(),但都无济于事 – 所以请帮我弄清楚我做错了什么?
.controller('AppCtrl',function($scope,Items,Auth,$state,$ionicHistory) { $scope.login = function(provider) { Auth.$authWithOAuthRedirect(provider).then(function(authData) { }).catch(function(error) { if (error.code === "TRANSPORT_UNAVAILABLE") { Auth.$authWithOAuthPopup(provider).then(function(authData) { }); } else { console.log(error); } }); }; $scope.logout = function() { Auth.$unauth(); $scope.authData = null; $window.location.reload(true); }; Auth.$onAuth(function(authData) { if (authData === null) { console.log("Not logged in yet"); $state.go('app.login'); } else { console.log("Logged in as",authData.uid); $ionicHistory.nextViewOptions({ disableBack: true }); $state.go('app.items'); } $scope.authData = authData; // This will display the user's name in our view }); })
<ion-view view-title="Members area"> <ion-content padding="true"> <div ng-if="!authData"> <buttonng-click="login('facebook')">Log In with Facebook</button> </div> <div ng-if="authData.facebook"> <div> <div>Hello {{authData.facebook.displayName}}!</div> </div> <buttonng-click="logout()">Log out</button> </div> </ion-content> </ion-view>
编辑:我通过使用$timeout来解决它:
$timeout(function(){ Auth.$onAuth(function(authData) { if (authData === null) { console.log("Not logged in yet"); $state.go('app.login'); } else { console.log("Logged in as",authData.uid); $ionicHistory.nextViewOptions({ disableBack: true }); $state.go('app.items'); } $scope.authData = authData; // This will display the user's name in our view }); },3000);
然而,这只是感觉不对(温和地放),并且必须有更好的方法,所以请建议一个.此外,我注意到高达3秒的延迟几乎不够(我发现建议500ms的资源很少就足够了,但在我的情况下,情况并非如此).
解决方法
这只发生在使用$authWithOAuthRedirect的浏览器中.该示例适用于cordova应用程序,因此这不应该是一个问题.
但如果你真的需要它,你可以跳过重定向并使用弹出窗口.
Auth.$authWithOAuthPopup(authMethod).then(function(authData) { console.dir(authData); });
angularjs – 来自Facebook的$authWithOAuthRedirect之后,Firebase $onAuth的authData错误
当我使用弹出窗口进行身份验证时,一切都按预期工作,但支持尽可能多的浏览器(iOS上的Chrome不支持弹出窗口,例如)我想要使用重定向进行身份验证($authWithOAuthRedirect) .
我已经确认我在Facebook中的设置是正确的(我的应用程序ID和秘密,例如)但是当我在使用重定向进行Facebook身份验证后重定向回我的应用程序时,$onAuth会触发,但我没有我的Facebook authData.
相反,我有匿名authData.有点背景;如果没有以其他方式验证所有用户,则匿名进行身份验证(例如,使用Facebook).
我无法找到为什么会这样 – 用户现在应该通过Facebook验证,并拥有Facebook authData.
在某些情况下,我的代码的例外情况如下:
用户单击登录按钮时触发
function logIn () { firebaseAuth .$authWithOAuthRedirect('facebook',function (error) { if (error) { console.log(error); } }); }
$onAuth(在我的Angular应用程序运行中)
function run ($rootScope,firebaseAuth,sessionStore) { $rootScope .$on('$routeChangeError',function (event,next,prev,error) { if (error === 'AUTH_required') { console.log(error); } }); $rootScope .$on('$routeChangeSuccess',current,prev) { $rootScope.title = current.$$route.title; }); firebaseAuth .$onAuth(onAuth); function onAuth (authData) { console.log(authData); } }
路由解析器以匿名方式对用户进行身份验证
function sessionState ($q,firebaseAuth) { var deferred = $q.defer(); firebaseAuth .$requireAuth() .then(deferred.resolve,guest); return deferred.promise; function guest () { firebaseAuth .$authAnonymously() .then(deferred.resolve,rejected); } function rejected () { deferred.reject('AUTH_required'); } }
路由解析器(sessionState)检查用户是否已经过身份验证,如果没有,则尝试匿名验证用户.
在Facebook身份验证重定向之后,用户将已经过身份验证,因此无需进行匿名身份验证.
但是,它们似乎是?由于$onAuth将authData记录到控制台,因此它是匿名的.
任何帮助都将非常感谢!我确信它与我的路由解析器有关,因为弹出式身份验证工作正常(路由已经解决).
编辑:我试图完全删除我的路由解析器,以防它导致问题,但它没有任何区别.用户只是“未经身份验证”,而不是通过Facebook($authWithOAuthRedirect)或匿名进行身份验证.
更新:我尝试使用Twitter和重定向传输进行身份验证,我遇到了完全相同的问题.我也尝试使用端口80,而不是端口3000,我的应用程序在本地提供,但没有快乐.
更新:当我在我的应用程序中关闭html5Mode模式 – 现在路由以#s开头 – $authWithOAuthRedirect完美运行.由此我只能假设$authWithOAuthRedirect不支持AngularJS的html5Mode.任何人都可以确认这是一个问题,还是我需要更改我的代码以支持html5Mode和authWithOAuthRedirect?
示例REPO以下是演示此问题的示例repo:https://github.com/jonathonoates/myapp
查看dist目录 – 您应该能够下载并运行应用程序以重现问题.在scripts / main.js中是应用程序的JS;我添加了几条评论,但这是非常自我解释的.
要重现问题:点击“Facebook登录”按钮,您将被重定向到Facebook进行身份验证. FB会将你重定向回应用程序,但这里存在问题 – 你将不会被验证,并且返回的authData将为null – 你会在控制台中看到这一点
更新:当我在html5Mode中添加hashPrefix时,例如
$locationProvider .html5Mode(true) .hashPrefix('!');
该应用程序正如我所期望的那样 – 通过Facebook验证和重定向传输工作.
几个小小的但是:
>网址有#?附加到它,并在浏览器的历史记录中可用/可见.
>这会用#重写URL!在不支持History.pushState(html5Mode)的浏览器中,由于’hashbang’,一些不太高级的搜索引擎可能会寻找HTML片段.
我将研究从Facebook重定向而不是使用hashPrefix来劫持URL.在URL中有一个__firebase_request_key,它可能很重要,例如
http://localhost:3000/#%3F&__firebase_request_key=
解决方法
我已经做了一个实验性修复,确保我们在重定向流结束时将URL恢复为“http://…/#”,Angular很满意,从而防止了有问题的重定向.如果你愿意,你可以在这里抓住它:https://mike-shared.firebaseapp.com/firebase.js
我将确保此修复程序进入下一版本的JS客户端.您可以留意我们的changelog以查看它何时发布.
关于reactjs – 放置firebase.auth()的位置.onAuthStateChanged()和react ajax放在哪里的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于@react-native-firebase/auth 不适用于 ios、angular – Firebase – 如何检测/观察Firebase用户何时验证其电子邮件,如onAuthStateChanged、angularjs – Firebase $authWithOAuthRedirect在没有页面刷新的情况下不会调用$onAuth、angularjs – 来自Facebook的$authWithOAuthRedirect之后,Firebase $onAuth的authData错误等相关内容,可以在本站寻找。
本文标签: