From 0f5c11535b80282ea4e722fc55b86c617486b62b Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Tue, 27 Oct 2020 18:13:14 +0100 Subject: [PATCH] Tweaks --- packages/sdk-js/src/handlers/auth.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/sdk-js/src/handlers/auth.ts b/packages/sdk-js/src/handlers/auth.ts index 487393f09d..12ef10e0a9 100644 --- a/packages/sdk-js/src/handlers/auth.ts +++ b/packages/sdk-js/src/handlers/auth.ts @@ -24,6 +24,10 @@ export class AuthHandler { this.storage = options.storage; this.mode = options.mode; this.autoRefresh = options.autoRefresh; + + if (this.autoRefresh) { + this.refresh(); + } } get token() { @@ -52,11 +56,14 @@ export class AuthHandler { } async refresh() { - const refreshToken = await this.storage.get('directus_refresh_token'); - const response = await this.axios.post('/auth/refresh', { - refresh_token: refreshToken, - mode: this.mode, - }); + const payload: Record = { mode: this.mode }; + + if (this.mode === 'json') { + const refreshToken = await this.storage.get('directus_refresh_token'); + payload['refresh_token'] = refreshToken; + } + + const response = await this.axios.post('/auth/refresh', payload); this.token = response.data.data.access_token;