aurelia-contrib / aurelia-open-id-connect

An aurelia adapter for the IdentityModel/oidc-client-js
https://zamboni-app.azurewebsites.net
MIT License
54 stars 18 forks source link

On login, Cannot read property 'trim' of undefined. #13

Closed shaunluttin closed 7 years ago

shaunluttin commented 7 years ago

Click login in Google Chrome. The page correctly navigates to the authorization server, and also throws this error:

ERROR [app-router] TypeError: Cannot read property 'trim' of undefined
    at relativeToFile (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:15464:25)
    at TemplatingRouteLoader.loadRoute (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:26871:52)
    at loadComponent (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:17147:24)
    at loadRoute (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:17120:12)
    at https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:17084:14
    at Array.map (native)
    at loadNewRoute (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:17083:31)
    at LoadRouteStep.run (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:17075:14)
    at next (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:15820:20)
    at iterate (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:16841:14)
    at processDeactivatable (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:16844:12)
    at CanDeactivatePreviousStep.run (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:16776:14)
    at next (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:15820:20)
    at https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:16269:16
    at tryCatcher (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:3394:23)
    at Promise._settlePromiseFromHandler (https://zamboni-app.azurewebsites.net/scripts/vendor-bundle.js:2594:31)
error @ vendor-bundle.js:13714
log @ vendor-bundle.js:14014
error @ vendor-bundle.js:14047
processResult @ vendor-bundle.js:17452
(anonymous) @ vendor-bundle.js:17405
tryCatcher @ vendor-bundle.js:3394
Promise._settlePromiseFromHandler @ vendor-bundle.js:2594
Promise._settlePromise @ vendor-bundle.js:2651
Promise._settlePromise0 @ vendor-bundle.js:2696
Promise._settlePromises @ vendor-bundle.js:2775
(anonymous) @ vendor-bundle.js:153
shaunluttin commented 7 years ago

The error is related to our login route.

{
    name: "login", nav: false, navigationStrategy: () => this.openIdConnect.login(), route: "login",
    settings: { roles: [OpenIdConnectRoles.Anonymous] },
},

The aurelia-templating-router is loading it like this. The config.moduleId is undefined, though, and so _aureliaPath.relativeToFile() throws the above error.

TemplatingRouteLoader.prototype.loadRoute = function loadRoute(router, config) {
    var childContainer = router.container.createChild();
    var instruction = {
        viewModel: (0,
        _aureliaPath.relativeToFile)(
            config.moduleId, 
            _aureliaMetadata.Origin.get(router.container.viewModel.constructor).moduleId),
            childContainer: childContainer,
            view: config.view || config.viewStrategy,
shaunluttin commented 7 years ago

Related? https://github.com/aurelia/router/issues/400 Related? https://github.com/aurelia/router/issues/386 Related? https://github.com/aurelia/documentation/issues/68

shaunluttin commented 7 years ago

Changing the navigationStrategy to set its moduleId to an empty string resolved the issue. @EisenbergEffect.

{
    name: "login", 
    nav: false, 
    navigationStrategy: (instruction) => {
        instruction.config.href = instruction.fragment;
        instruction.config.moduleId = instruction.fragment;
        this.openIdConnect.login();
    }, 
    route: "login",
    settings: { roles: [OpenIdConnectRoles.Anonymous] },
},
shaunluttin commented 7 years ago

The final resolution is to set href, moduleId, and redirect.

{
    name: "login",
    nav: false,
    navigationStrategy: (instruction) => {
        instruction.config.href = instruction.fragment;
        instruction.config.moduleId = instruction.fragment;
        instruction.config.redirect = instruction.fragment;
        this.openIdConnect.login();
    },
    route: "login",
    settings: {
        roles: [OpenIdConnectRoles.Anonymous]
    },
},