Instructor: To make use of the user roles we've got from Domino, we're going to go into our node application, our service.js. We're going to create a new route, and we're going to get hold of those roles. For now, for testing purposes, we'll have a direct route to load up the roles.
Similar to previously, the first thing we need to do is get hold of the node DOM off social ID that we've set in our header. If we don't have one, we're going to bail because our application needs this authentication header. We'll set up the options. We're going to pass to our request promise.
We also need to make sure that the request promise library actually returns JSON data. We do that by setting JSON true in the options. Our request promise will be called passing the options, and then we'll handle the response or any errors.
We'll deconstruct the headers and bodies for the response, look for a Domino authentication failure. If we get pass that point, we'll just send back the actual response we get back from Domino, which should be some JSON data. We actually use the JSON method of express to send back correctly-formatted headers. If we get an error, we'll handle that, as well.
We're now going to test this route in our client application. Going back into our index directional page, we're going to add a new button. We'll add it next to the get Domino data we had previously. This time we'll get user roles, or a new function called get user roles, and we'll write the script bot for that down here.
First thing we do is set up an options object to pass to our Ajax call using the a-axis library. Our URL is going to be our new route, which is user roles. We'll pick up the node DOM off social ID that we've set in our local storage after we've logged in. Remember this won't work until you have logged in.
We'll set up our custom header with a value, and now, we make our call using the a-axis library. For now, we're just going to log out the result which should be JSON data containing our user roles. We'll make sure to caption the areas, as well, and we'll also log those to the console. OK, we'll start our node server up, open the index page and test it.
I fired up my node server, launched my index test page. Just to confirm, I still my have node DOM off social ID in my local storage. It's still a valid identification. If I click the get user roles button, look at my console, I get back some data.
If I look in the network tab, I can now see that the response coming back is actually JSON data with the roles and my username. We can now use this data in our client application.