From 7c332d0f43f3580ab7d06ad3714ce1827d7268e7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 18 Mar 2024 10:08:57 -0400 Subject: [PATCH] refactor: add sdk getter --- app/data/auth-provider.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index af8db9a..17c0dcb 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -33,10 +33,8 @@ export type Identity = { } export class PortalAuthProvider implements RequiredAuthProvider { - private sdk: Sdk; - constructor(apiUrl: string) { - this.sdk = Sdk.create(apiUrl); + this._sdk = Sdk.create(apiUrl); const methods: Array = [ 'login', @@ -55,8 +53,18 @@ export class PortalAuthProvider implements RequiredAuthProvider { }); } + private _sdk: Sdk; + + get sdk(): Sdk { + return this._sdk; + } + + public static create(apiUrl: string): AuthProvider { + return new PortalAuthProvider(apiUrl); + } + async login(params: AuthFormRequest): Promise { - const ret = await this.sdk.account().login({ + const ret = await this._sdk.account().login({ email: params.email, password: params.password, }) @@ -77,14 +85,14 @@ export class PortalAuthProvider implements RequiredAuthProvider { } async logout(params: any): Promise { - let ret = await this.sdk.account().logout(); + let ret = await this._sdk.account().logout(); return {success: ret, redirectTo: "/login"}; } async check(params?: any): Promise { this.maybeSetupAuth(); - const ret = await this.sdk.account().ping(); + const ret = await this._sdk.account().ping(); return {authenticated: ret, redirectTo: ret ? undefined : "/login"}; } @@ -95,7 +103,7 @@ export class PortalAuthProvider implements RequiredAuthProvider { } async register(params: RegisterFormRequest): Promise { - const ret = await this.sdk.account().register({ + const ret = await this._sdk.account().register({ email: params.email, password: params.password, first_name: params.firstName, @@ -118,7 +126,7 @@ export class PortalAuthProvider implements RequiredAuthProvider { async getIdentity(params?: Identity): Promise { this.maybeSetupAuth(); - const ret = await this.sdk.account().info(); + const ret = await this._sdk.account().info(); if (!ret) { return {identity: null}; @@ -138,13 +146,9 @@ export class PortalAuthProvider implements RequiredAuthProvider { const cookies = new Cookies(); const jwtCookie = cookies.get('auth_token'); if (jwtCookie) { - this.sdk.setAuthToken(jwtCookie); + this._sdk.setAuthToken(jwtCookie); } } - - public static create(apiUrl: string): AuthProvider { - return new PortalAuthProvider(apiUrl); - } } interface RequiredAuthProvider extends AuthProvider {