离子火力点登录身份验证无法正常工作(电子邮件) [英] Ionic firebase login Auth not functioning (email)
问题描述
一切似乎使用的登录/注销时工作。但是当我做一个初步的离子服务我得到位于登录页面,但如果我再更改网址为 菜单/地图我可以进入地图的.html这不应该是可能的。同样的事情发生了,我点击后,我的注销按钮。
请告诉我错了我的身份验证code?
app.js
angular.module('启动',['离子','火力'])
的.config(函数($ ionicConfigProvider){
$ ionicConfigProvider.scrolling.jsScrolling(真);
})
.RUN(函数($ ionicPlatform,$ rootScope,验证,$州){
$ ionicPlatform.ready(函数(){
如果(window.cordova&安培;&安培; window.cordova.plugins.Keyboard){
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(真);
}
如果(window.StatusBar){
StatusBar.styleDefault();
}
});
// stateChange事件
$ rootScope。在$($ stateChangeStart功能(事件,toState,toParams,fromState,fromParams){
如果(toState.authRequired&放大器;&放大器;!Auth.isAuthenticated()){//假设AuthService持有认证逻辑
//用户没有通过验证
$ state.go(登录);
。事件preventDefault();
}
});
})
的.config(函数($ stateProvider,$ urlRouterProvider){
$ stateProvider
.STATE('登陆',{
网址:'/',
templateUrl:'模板/登录/ login.html的,
控制器:'userCtrl
}) .STATE('应用',{
网址:'/菜单,
摘要:真实,
templateUrl:'模板/ menu.html
})
.STATE('app.map',{
网址:'/图,
观点:{
公共地图:{
templateUrl:'模板/ map.html',
authRequired:真
}
}
})
$ urlRouterProvider.otherwise(/);
})
.constant('FIREBASE_ROOT','https://开头<&MYAPP GT; .firebaseio.com');
service.js
angular.module('启动器')
.factory(验证功能($ firebaseAuth,FIREBASE_ROOT){
VAR usersRef =新的火力地堡(FIREBASE_ROOT);
返回$ firebaseAuth(usersRef);
});
controller.js
angular.module('启动器')
.controller('userCtrl',函数($范围,$状态,验证){
$ scope.login =功能(电子邮件,密码){
验证。$ authWithPassword({
电子邮件:电子邮件,
密码:密码
}),然后(功能(的authData){
$ state.go(app.map);
})赶上(功能(错误){
console.error(错误:+误差);
});
};
$ scope.logout =功能(){
。验证$ UNAUTH();
$ state.go(登录);
};
})
显然,这是一个常见的问题。离子团队增加了关于如何解决它的一些说明;白名单与科尔多瓦白名单,插件您的域。
您可以阅读所有关于它在这里: http://docs.ionic.io/docs/科尔多瓦白名单
Everything seems to work when using login/logout. But when i do a initial "ionic serve" i get located to the login page but if i then change the url to "/menu/map" i can get into map.html which should not be possible. Same thing happens after i click my "logout" button.
Whats wrong with my authentication code?
app.js
angular.module('starter', ['ionic', 'firebase'])
.config(function($ionicConfigProvider) {
$ionicConfigProvider.scrolling.jsScrolling(true);
})
.run(function($ionicPlatform, $rootScope, Auth, $state) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
//stateChange event
$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams){
if (toState.authRequired && !Auth.isAuthenticated()){ //Assuming the AuthService holds authentication logic
// User isn’t authenticated
$state.go("login");
event.preventDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('login', {
url: '/',
templateUrl: 'templates/login/login.html',
controller: 'userCtrl'
})
.state('app', {
url: '/menu',
abstract: true,
templateUrl: 'templates/menu.html'
})
.state('app.map', {
url: '/map',
views: {
'public-map': {
templateUrl: 'templates/map.html',
authRequired: true
}
}
})
$urlRouterProvider.otherwise("/");
})
.constant('FIREBASE_ROOT', 'https://<MYAPP>.firebaseio.com');
service.js
angular.module('starter')
.factory("Auth", function($firebaseAuth, FIREBASE_ROOT) {
var usersRef = new Firebase(FIREBASE_ROOT);
return $firebaseAuth(usersRef);
});
controller.js
angular.module('starter')
.controller('userCtrl', function($scope, $state, Auth) {
$scope.login = function(email, password) {
Auth.$authWithPassword({
email: email,
password: password
}).then(function(authData) {
$state.go("app.map");
}).catch(function(error) {
console.error("ERROR: " + error);
});
};
$scope.logout = function() {
Auth.$unauth();
$state.go("login");
};
})
Apparently it's a common issue. The Ionic Team has added some instructions on how to solve it; whitelist your domain with the cordova-whitelist-plugin.
You can read all about it here: http://docs.ionic.io/docs/cordova-whitelist
这篇关于离子火力点登录身份验证无法正常工作(电子邮件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!