From 21953bf6d78568aea4650a74ec5bd85f6db607d0 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 6 Feb 2020 13:18:09 -0800 Subject: [PATCH] adds getter for sessionid Signed-off-by: andrew --- src/ThreadsConfig.ts | 15 ++++++++------- src/index.ts | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ThreadsConfig.ts b/src/ThreadsConfig.ts index 7570561ae..ad831659b 100644 --- a/src/ThreadsConfig.ts +++ b/src/ThreadsConfig.ts @@ -1,13 +1,14 @@ import { grpc } from '@improbable-eng/grpc-web' import { Config } from '@textile/threads-client' import axios, { AxiosRequestConfig } from 'axios' + type Session = { id: string session_id: string } export class ThreadsConfig extends Config { public host: string - public session?: string + public sessionId?: string constructor( public token: string, public deviceId: string, @@ -23,7 +24,7 @@ export class ThreadsConfig extends Config { } async start(sessionId?: string) { if (sessionId !== undefined) { - this.session = sessionId + this.sessionId = sessionId return } await this.refreshSession() @@ -51,24 +52,24 @@ export class ThreadsConfig extends Config { if (resp.status !== 200) { new Error(resp.statusText) } - this.session = resp.data.session_id + this.sessionId = resp.data.session_id } _wrapMetadata(values?: { [key: string]: any }): { [key: string]: any } | undefined { - if (!this.session) { + if (!this.sessionId) { return values } const response = values ?? {} if ('Authorization' in response || 'authorization' in response) { return response } - response['Authorization'] = `Bearer ${this.session}` + response['Authorization'] = `Bearer ${this.sessionId}` return response } _wrapBrowserHeaders(values: grpc.Metadata): grpc.Metadata { - if (!this.session) { + if (!this.sessionId) { return values } - values.set('Authorization', `Bearer ${this.session}`) + values.set('Authorization', `Bearer ${this.sessionId}`) return values } } diff --git a/src/index.ts b/src/index.ts index 72333aed5..cd92e96b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,6 +55,10 @@ export class API { return this } + get sessionId(): string | undefined { + return this._threadsConfig.sessionId + } + get threadsConfig(): ThreadsConfig { return this._threadsConfig }