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;