Navigation Menu

Skip to content

Commit

Permalink
fix(auth/client): fixes persistent error ref
Browse files Browse the repository at this point in the history
apprently axios does some header swapping from headers.common to headers. which will essentially
persist the token indefinitely. This commit has some self-defense character, hence we should review
this at a later time
  • Loading branch information
eljefedelrodeodeljefe committed Feb 6, 2019
1 parent 18cafee commit 060d538
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/client.ts
Expand Up @@ -5,7 +5,9 @@ import { environment } from './environment'
export interface ClientOptions {
base?: string
timeout?: number
headers?: object
headers?: {
[key: string]: any;
}
token?: string
}

Expand Down Expand Up @@ -67,6 +69,8 @@ export class Client {
}

clearDefaults(): void {
Client.instance.axiosInstance.defaults.headers.common['Authorization'] = undefined
Client.instance.axiosInstance.defaults.headers['Authorization'] = undefined
Client.instance.axiosInstance.defaults.headers.common = {
...defaultHeaders
}
Expand Down
4 changes: 4 additions & 0 deletions src/tillhub-js.ts
Expand Up @@ -105,6 +105,10 @@ export class TillhubClient extends events.EventEmitter {
headers: {}
}

if ((options.credentials as TokenAuth).token && clientOptions.headers) {
clientOptions.headers['Authorization'] = `Bearer ${(options.credentials as TokenAuth).token}`
}

this.auth = new v1.Auth(authOptions)
this.http = Client.getInstance(clientOptions).setDefaults(clientOptions)
return true
Expand Down

0 comments on commit 060d538

Please sign in to comment.