Ich habe eine AngularJS-Anwendung, die ich mit Firebase verwendet habe, um Daten zu erhalten.Firebase 3.0-Authentifizierung mit AngularJS-Anwendung
Jetzt habe ich daran gearbeitet, meinen Auth-Code gemäß den Firebase 3.0-Richtlinien zu refaktorieren.
Das Problem, mit dem ich konfrontiert bin, ist, dass bei der Anmeldung der in der app.js-Datei definierte Status "classifieds" nicht geladen wird. Die Konsole wirft auch keinen Fehler.
In meiner Anwendung möchte ich, dass mein Benutzer bei der ersten Instanz auf die Anmeldeseite weitergeleitet wird. Deshalb habe ich den folgenden Code in meiner app.js-Datei. Ich habe keinen Code in dieser Datei umstrukturiert. Bitte lassen Sie mich wissen, wenn dies das Problem ist.
angular
.module('ngClassifieds', ['ngMaterial', 'ui.router', 'firebase'])
.run(["$rootScope", "$state", function($rootScope, $state) {
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
// We can catch the error thrown when the $requireAuth promise is rejected
// and redirect the user back to the home page
if (error === "AUTH_REQUIRED") {
$state.go("auth");
}
});
}])
.config(function($mdThemingProvider, $stateProvider, $urlRouterProvider) {
$mdThemingProvider
.theme('default')
.primaryPalette('blue-grey')
.accentPalette('orange')
// .backgroundPalette('blue-grey');
$urlRouterProvider.otherwise('/auth');
$stateProvider
.state('auth', {
url: '/auth',
templateUrl: 'components/auth/auth.tpl.html',
controller: 'authCtrl',
})
$stateProvider
.state('classifieds', {
url: '/notes',
templateUrl: 'components/classifieds/classifieds.tpl.html',
controller: 'classifiedsCtrl',
resolve: {
// controller will not be loaded until $requireAuth resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["auth", function(auth) {
// $requireAuth returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return auth.ref.$requireAuth();
}]
}
})
Das folgende ist meine auth.ctr.js Datei:
(function() {
"use strict";
angular
.module('ngClassifieds')
.controller('authCtrl', function($scope, auth, $state, $firebaseAuth) {
var auth = $firebaseAuth();
$scope.login = function() {
auth
.$signInWithEmailAndPassword($scope.email, $scope.password)
.then(function(result) {
$state.go('classifieds');
})
.catch(function(error) {
$scope.error = error;
});
}
});
})();
Die folgende meine auth.fac.js ist:
(function() {
"use strict";
angular
.module('ngClassifieds')
.factory('auth', function($firebaseAuth) {
function signOut() {
return firebase.auth().signOut()
.then(function() {
console.log('signed out')
})
.catch(function(error) {
console.log(error);
});
}
return {
signOut: signOut
}
});
})();
Auch meine index.html hat die notwendige Informationen pro Firebase 3.0 Dokumentation:
<script src="https://www.gstatic.com/firebasejs/3.6.9/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "XXX",
authDomain: "XXX.firebaseapp.com",
databaseURL: "https://XXXX.firebaseio.com",
storageBucket: "XXX.appspot.com",
messagingSenderId: "XXX"
};
firebase.initializeApp(config);
</script>
<script src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"></script>
Ich würde mich über jegliche Hinweise zu diesem Thema freuen.
Dank
Bitte fügen Sie einen Kolben oder etwas ähnliches, das dieses Problem reproduziert. Es ist sehr schwer so zu debuggen. –
Mögliches Duplikat von [Authentifizierungsproblem bei der Migration von AngularJS-Anwendung und Firebase 2.xx zu Firebase 3.xx] (http://stackoverflow.com/questions/42137906/authentication-issue-with-migrating-angularjs-application-and-firebase -2-xx-to) –