How does the server and client user login blend in together?

57 views Asked by At

I set up a mean stack based on http://mean.io

I managed to get it running but I'm confused with the user authentication flow.

The main thing that is confusing me is the distinction between server/views and public/views.

I understand that when I want to require user auth I can do app.get with auth.requiresLogin.

But how does this mix in with the angular client side of things? How do I make the angular views available only when logged in.

My objective is to have the following:

When users go to / I want them to see a basic message if they are not logged in.

When they do log in, in / I want them to see my angular app.

I'm confused as to how to achieve that.

How do I structure my app for this purpose? Can I check in the template whether a user is logged in?

1

There are 1 answers

2
Michael On

You use routeProvider:

.config(['$routeProvider', '$locationProvider',

    function ($routeProvider, $locationProvider) {

        var access = routingConfig.accessLevels;

        $routeProvider.when('/',
        {
            templateUrl:    'partials/...',
            controller:     yourController,
            access:         access.user
        });

        $routeProvider.when('/',
        {
            templateUrl:    'partials/...',
            access:         access.anon
        });

    }]);

This example has to work.