Aurelia side side views: add an auth header to the view / viewmodel HTTP load request

I am using the Aurelia skeleton sample (skeleton-esnext-aspnetcore) with C # / MVC backend from: https://github.com/aurelia/skeleton-navigation/tree/master/skeleton-esnext-aspnetcore

To support server side views, I updated the view locator prototype (ViewLocator.prototype.convertOriginToViewUrl) in main.js to request the view / viewmodel files from the server. Details here: http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/app-configuration-and-startup/9

This works great and the sample / viewmodel of the sample is successfully loaded / loaded from the server by the JS system.

I would like to add a custom auth header to the http view / viewmodel request to identify the user on the backend server. How do I set this up in Aurelia?

I have an existing service using the Aurelia fetch client / interceptors client that sends auth headers to the API. I tried to initialize the fetch client config earlier in app / main.js, but that didn't seem to solve the problem. Thank!

0


source to share


1 answer


I found a link to the SystemJS config API: https://github.com/systemjs/systemjs/blob/master/docs/config-api.md

As a quick test, I've added the following code to an existing script block in index.html:

 <script>
    System.config({
        meta: {
            '*': {
                'authorization': 'bearer 123'
            }  
        }
    });
    System.import('aurelia-bootstrapper');
</script>

      



After verifying the header was added, I was able to confirm that the code could be moved to a regular class like main.js:

  System.config({
      meta: {
          '*': {
              'authorization': 'bearer 123456'
          }  
      }
  });

      

+1


source







All Articles