format errors from auth-jwt plugin similarly to other authentication errors (#6553)

This commit is contained in:
Matthew Irish 2019-04-09 12:42:51 -05:00 committed by GitHub
parent 22587672ec
commit ee39025cf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -173,7 +173,7 @@ export default Component.extend(DEFAULTS, {
showLoading: or('isLoading', 'authenticate.isRunning', 'fetchMethods.isRunning', 'unwrapToken.isRunning'), showLoading: or('isLoading', 'authenticate.isRunning', 'fetchMethods.isRunning', 'unwrapToken.isRunning'),
handleError(e) { handleError(e, prefixMessage = true) {
this.set('loading', false); this.set('loading', false);
if (!e.errors) { if (!e.errors) {
return e; return e;
@ -184,7 +184,8 @@ export default Component.extend(DEFAULTS, {
} }
return error; return error;
}); });
this.set('error', `Authentication failed: ${errors.join('.')}`); let message = prefixMessage ? 'Authentication failed: ' : '';
this.set('error', `${message}${errors.join('.')}`);
}, },
authenticate: task(function*(backendType, data) { authenticate: task(function*(backendType, data) {
@ -239,5 +240,12 @@ export default Component.extend(DEFAULTS, {
} }
return this.authenticate.unlinked().perform(backend.type, data); return this.authenticate.unlinked().perform(backend.type, data);
}, },
handleError(e) {
if (e) {
this.handleError(e, false);
} else {
this.set('error', null);
}
},
}, },
}); });

View file

@ -56,7 +56,7 @@
{{/if}} {{/if}}
{{#if (or (eq this.selectedAuthBackend.type "jwt") (eq this.selectedAuthBackend.type "oidc"))}} {{#if (or (eq this.selectedAuthBackend.type "jwt") (eq this.selectedAuthBackend.type "oidc"))}}
<AuthJwt <AuthJwt
@onError={{action (mut this.error)}} @onError={{action "handleError"}}
@onLoading={{action (mut this.isLoading)}} @onLoading={{action (mut this.isLoading)}}
@onToken={{action (mut this.token)}} @onToken={{action (mut this.token)}}
@namespace={{this.namespace}} @namespace={{this.namespace}}