From 4c4b84905cd475ce150e5f30bfde9f7f15f4fea3 Mon Sep 17 00:00:00 2001 From: David de Boer Date: Tue, 2 Feb 2021 09:35:47 +0100 Subject: [PATCH] Fix authentication --- src/store.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/store.ts b/src/store.ts index a0eb5e0c..57a80791 100644 --- a/src/store.ts +++ b/src/store.ts @@ -71,30 +71,28 @@ export class GraphDbDataStore implements Store { } private async authenticate(): Promise { - if (this.username === null || this.password === null) { + if (this.username === undefined || this.password === undefined) { return new Headers(); } - if (this.token !== undefined) { - return new Headers(); - } - - const response = await fetch(this.url + '/rest/login/' + this.username, { - method: 'POST', - headers: {'X-Graphdb-Password': this.password!}, - }); - - if (!response.ok) { - throw Error( - 'Could not authenticate username ' + - this.username + - ' with GraphDB; got status code ' + - response.status - ); + if (this.token === undefined) { + const response = await fetch(this.url + '/rest/login/' + this.username, { + method: 'POST', + headers: {'X-Graphdb-Password': this.password!}, + }); + + if (!response.ok) { + throw Error( + 'Could not authenticate username ' + + this.username + + ' with GraphDB; got status code ' + + response.status + ); + } + + this.token = response.headers.get('Authorization')!; } - this.token = response.headers.get('Authorization')!; - return new Headers({Authorization: this.token}); }