vendredi 26 mai 2017

Managing user roles in emberjs?

I have a nodejs api as shown below

route.post("/token",function(req,res){
    authLib
        .checkForm(req.body)
        .then(authLib.findUser)
        .then(authLib.isValidUser)
        .then(authLib.authenticate)
        .then(authLib.genToken)
        .then((token)=>{
            res
                .status(200)
                .json({'access_token': token});
        })
        .catch((err)=>{
            res
                .status(400)
                .json({'error': err.message});
        });
});

The model for user contains a field with user role. Each user role has a different dashboard. I have implemented ember-simple-auth with oauth2-password-grant and the template for dashboard is as shown below


    
    

    
    


The problem is how can i distinguish between the user roles. One method could be to use ajax requests to fetch role but that would mean an additional XHR request for all views. Also another problem with using XHR in Ember.$ is that the authorization token is not attached to request. What is the best way to solve this issue ?




Aucun commentaire:

Enregistrer un commentaire