How to make simple role based authorization in AngularJS and FireBase?
<p>I want to make a simple role based authorization in AngularJS and FireBase (admin, user).
I made the base authorization, and routing (look at 3 files below).</p>
<p>I found a <a href="https://github.com/colthreepv/angular-login-example" rel="nofollow noreferrer">repository</a> in github and <a href="https://arthur.gonigberg.com/2013/06/29/angularjs-role-based-auth/" rel="nofollow noreferrer">article</a> but code is too hard for me.
Is there an easier way? How do I change my code to add this functionality?
I would be grateful for links to articles and repositories that can help me.</p>
<hr />
<p><strong>app.js</strong></p>
<pre><code>var app = angular.module( 'journalApp', [ 'firebase', 'ngRoute' ] );

app.constant( 'FIREBASE', '&lt;FIREBASE URL&gt;' );

app.config( [ '$routeProvider', '$locationProvider', function( $routeProvider, $locationProvider ) {

    $routeProvider.when( '/login', {
        templateUrl: 'views/login.html',
        controller: 'loginCtrl',
        controllerAs: 'loginCtl'
    } );

    $routeProvider.when( '/logout', {
        templateUrl: 'views/login.html',
        controller: 'loginCtrl',
        controllerAs: 'loginCtl',
        resolve: {
            &quot;logout&quot;: [ &quot;authService&quot;, function( authService ) {
                authService.signOut();
            }]
        }
    } );

    $routeProvider.when( '/', {
        templateUrl: 'views/dashboard.html',
        resolve: {
            &quot;currentAuth&quot;: [ &quot;authService&quot;, function( authService ) {
                var auth = authService.auth();
                return auth.$requireSignIn();
            }]
        }
    });

    $routeProvider.otherwise( {
        redirectTo: '/'
    } );

    $locationProvider.html5Mode( true );

} ] );

app.run( [ &quot;$rootScope&quot;, &quot;$location&quot;, function( $rootScope, $location ) {
    $rootScope.$on(&quot;$routeChangeError&quot;, function(event, next, previous, error) {
        if (error === &quot;AUTH_REQUIRED&quot;) {
            $location.path(&quot;/login&quot;);
        }
    });
} ] );
</code></pre>
<hr />
<p><strong>loginCtrl.js</strong></p>
<pre><code>app.controller( 'loginCtrl', [ 'authService', function( authService ) {
    var self = this;

    self.signUp = function() {
        authService.createUser(self.email, self.password);
    };

    self.logIn = function() {
        authService.authUser(self.loginEmail, self.loginPassword);
    };

    self.signOut = function() {
        authService.signOut();
    };
}]);
</code></pre>
<hr />
<p><strong>authFactory.js</strong></p>
<pre><code>app.factory( 'authService',  [ '$firebaseAuth', '$window', function( $firebaseAuth, $window ) {

    var authService = {};

    var auth = $firebaseAuth(firebase.auth());

    authService.createUser = function(email, password) {
        auth.$createUserWithEmailAndPassword( email, password );
    };

    authService.authUser = function( email, password ) {
        auth.$signInWithEmailAndPassword( email, password ).then(function( user ) {
            $window.location.href = &quot;/&quot;;
        }, function( error ) {
            var errorCode = error.code;
            var errorMessage = error.message;
            console.info( &quot;Error in authUser - errorCode: &quot; + errorCode + &quot;. errorMessage: &quot; + errorMessage);
        });
    };

    authService.signOut = function() {
        auth.$signOut();
    };

    authService.auth = function() {
        return auth;
    };

    return authService;
}]);
</code></pre>
<hr />