Merge branch 'bvander/minor-auth-messages' into 'master'

Auth error messages to user

See merge request grassrootseconomics/cic-staff-client!39
This commit is contained in:
Blair Vanderlugt 2021-06-30 15:57:16 +00:00
commit 0ee8c7e6c8
3 changed files with 25 additions and 22 deletions

View File

@ -59,7 +59,9 @@ export class ErrorInterceptor implements HttpInterceptor {
this.router.navigateByUrl('/auth').then(); this.router.navigateByUrl('/auth').then();
break; break;
case 403: // forbidden case 403: // forbidden
alert('Access to resource is not allowed!'); this.errorDialogService.openDialog(
{ message: 'Access to resource is not allowed (Error 403)'})
//alert('Access to resource is not allowed!');
break; break;
} }
// Return an observable with a user-facing error message. // Return an observable with a user-facing error message.

View File

@ -48,8 +48,9 @@ export class AuthService {
} }
getWithToken(): Promise<boolean> { getWithToken(): Promise<boolean> {
const sessionToken = this.getSessionToken()
const headers = { const headers = {
Authorization: 'Bearer ' + this.getSessionToken, Authorization: 'Bearer ' + sessionToken,
'Content-Type': 'application/json;charset=utf-8', 'Content-Type': 'application/json;charset=utf-8',
'x-cic-automerge': 'none', 'x-cic-automerge': 'none',
}; };
@ -93,36 +94,36 @@ export class AuthService {
async login(): Promise<boolean> { async login(): Promise<boolean> {
if (this.getSessionToken()) { if (this.getSessionToken()) {
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN')); sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
} else { }
const o = await this.getChallenge(); const o = await this.getChallenge();
const r = await signChallenge( const r = await signChallenge(
o.challenge, o.challenge,
o.realm, o.realm,
environment.cicMetaUrl, environment.cicMetaUrl,
this.mutableKeyStore this.mutableKeyStore
); );
const tokenResponse = await this.sendSignedChallenge(r).then((response) => { const tokenResponse = await this.sendSignedChallenge(r)
.then((response) => {
const token = response.headers.get('Token'); const token = response.headers.get('Token');
if (token) { if (token) {
return token; return token;
} }
if (response.status === 401) { if (response.status === 401) {
throw new HttpError('You are not authorized to use this system', response.status); throw new HttpError('You are not authorized to use this system', response.status);
} }
if (!response.ok) { if (!response.ok) {
throw new HttpError('Unknown error from authentication server', response.status); throw new HttpError('Unknown error from authentication server', response.status);
} }
}); });
if (tokenResponse) { if (tokenResponse) {
this.setSessionToken(tokenResponse); this.setSessionToken(tokenResponse);
this.setState('Click button to log in'); //this.setState('Click button to log in');
return true; return true;
}
return false;
} }
return false;
} }
loginView(): void { loginView(): void {

View File

@ -58,7 +58,7 @@ export class AuthComponent implements OnInit {
} }
} catch (HttpError) { } catch (HttpError) {
this.errorDialogService.openDialog({ this.errorDialogService.openDialog({
message: HttpError.message, message: "Failed to login please try again.",
}); });
} }
} }