From b65bd12c8abbf53b675ff8ab3f60b95cec70017e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 19 Mar 2024 10:12:13 -0400 Subject: [PATCH] feat: implement updatePassword --- app/data/auth-provider.ts | 41 ++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index f7c211d..9145763 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -31,6 +31,11 @@ export type Identity = { email: string; } +export type UpdatePasswordFormRequest = { + currentPassword: string; + newPassword: string; +} + export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { const maybeSetupAuth = (): void => { const jwt = sdk.account().jwtToken; @@ -64,7 +69,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { async logout(params: any): Promise { let ret = await sdk.account().logout(); - return { success: ret, redirectTo: "/login" }; + return {success: ret, redirectTo: "/login"}; }, async check(params?: any): Promise { @@ -74,11 +79,11 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { maybeSetupAuth(); } - return { authenticated: ret, redirectTo: ret ? undefined : "/login" }; + return {authenticated: ret, redirectTo: ret ? undefined : "/login"}; }, async onError(error: any): Promise { - return { logout: true }; + return {logout: true}; }, async register(params: RegisterFormRequest): Promise { @@ -88,19 +93,37 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { first_name: params.firstName, last_name: params.lastName, }); - return { success: ret, redirectTo: ret ? "/dashboard" : undefined }; + return {success: ret, redirectTo: ret ? "/dashboard" : undefined}; }, async forgotPassword(params: any): Promise { - return { success: true }; + return {success: true}; }, - async updatePassword(params: any): Promise { - return { success: true }; + async updatePassword(params: UpdatePasswordFormRequest): Promise { + maybeSetupAuth(); + const ret = await sdk.account().updatePassword(params.currentPassword, params.newPassword); + + if (ret) { + if (ret instanceof Error) { + return { + success: false, + error: ret + } + } + + return { + success: true + } + } else { + return { + success: false + } + } }, async getPermissions(params?: Record): Promise { - return { success: true }; + return {success: true}; }, async getIdentity(params?: Identity): Promise { @@ -108,7 +131,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { const ret = await sdk.account().info(); if (!ret) { - return { identity: null }; + return {identity: null}; } const acct = ret as AccountInfoResponse;