From 7c69cbff8d0483db2160252ef67cf5314a096251 Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Wed, 19 Feb 2025 19:28:27 -0600 Subject: [PATCH] Add client_id to reset pwd --- src/lib/api.ts | 12 ++++++------ src/lib/main.tsx | 27 +++++++++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/lib/api.ts b/src/lib/api.ts index ec16d42..8117330 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -288,12 +288,12 @@ export async function changePassword(currentPassword: string, newPassword: strin ); } -export async function initiateGitHubAuth(inviteCode?: string): Promise { +export async function initiateGitHubAuth(client_id: string, inviteCode?: string): Promise { try { - return await encryptedApiCall<{ invite_code?: string }, GithubAuthResponse>( + return await encryptedApiCall<{ invite_code?: string; client_id: string }, GithubAuthResponse>( `${apiUrl}/auth/github`, "POST", - inviteCode ? { invite_code: inviteCode } : {}, + inviteCode ? { invite_code: inviteCode, client_id } : { client_id }, undefined, "Failed to initiate GitHub auth" ); @@ -355,12 +355,12 @@ export type GoogleAuthResponse = { csrf_token: string; }; -export async function initiateGoogleAuth(inviteCode?: string): Promise { +export async function initiateGoogleAuth(client_id: string, inviteCode?: string): Promise { try { - return await encryptedApiCall<{ invite_code?: string }, GoogleAuthResponse>( + return await encryptedApiCall<{ invite_code?: string; client_id: string }, GoogleAuthResponse>( `${apiUrl}/auth/google`, "POST", - inviteCode ? { invite_code: inviteCode } : {}, + inviteCode ? { invite_code: inviteCode, client_id } : { client_id }, undefined, "Failed to initiate Google auth" ); diff --git a/src/lib/main.tsx b/src/lib/main.tsx index 5a492fa..f123219 100644 --- a/src/lib/main.tsx +++ b/src/lib/main.tsx @@ -188,8 +188,13 @@ export type OpenSecretContextType = { refetchUser: () => Promise; changePassword: typeof api.changePassword; refreshAccessToken: typeof api.refreshToken; - requestPasswordReset: typeof api.requestPasswordReset; - confirmPasswordReset: typeof api.confirmPasswordReset; + requestPasswordReset: (email: string, hashedSecret: string) => Promise; + confirmPasswordReset: ( + email: string, + alphanumericCode: string, + plaintextSecret: string, + newPassword: string + ) => Promise; initiateGitHubAuth: (inviteCode: string) => Promise; handleGitHubCallback: (code: string, state: string, inviteCode: string) => Promise; initiateGoogleAuth: (inviteCode: string) => Promise; @@ -360,8 +365,8 @@ export const OpenSecretContext = createContext({ refetchUser: async () => {}, changePassword: api.changePassword, refreshAccessToken: api.refreshToken, - requestPasswordReset: api.requestPasswordReset, - confirmPasswordReset: api.confirmPasswordReset, + requestPasswordReset: async () => {}, + confirmPasswordReset: async () => {}, initiateGitHubAuth: async () => ({ auth_url: "", csrf_token: "" }), handleGitHubCallback: async () => {}, initiateGoogleAuth: async () => ({ auth_url: "", csrf_token: "" }), @@ -572,7 +577,7 @@ export function OpenSecretProvider({ const initiateGitHubAuth = async (inviteCode: string) => { try { - return await api.initiateGitHubAuth(inviteCode); + return await api.initiateGitHubAuth(clientId, inviteCode); } catch (error) { console.error("Failed to initiate GitHub auth:", error); throw error; @@ -597,7 +602,7 @@ export function OpenSecretProvider({ const initiateGoogleAuth = async (inviteCode: string) => { try { - return await api.initiateGoogleAuth(inviteCode); + return await api.initiateGoogleAuth(clientId, inviteCode); } catch (error) { console.error("Failed to initiate Google auth:", error); throw error; @@ -655,8 +660,14 @@ export function OpenSecretProvider({ requestNewVerificationEmail: api.requestNewVerificationCode, changePassword: api.changePassword, refreshAccessToken: api.refreshToken, - requestPasswordReset: api.requestPasswordReset, - confirmPasswordReset: api.confirmPasswordReset, + requestPasswordReset: (email: string, hashedSecret: string) => + api.requestPasswordReset(email, hashedSecret, clientId), + confirmPasswordReset: ( + email: string, + alphanumericCode: string, + plaintextSecret: string, + newPassword: string + ) => api.confirmPasswordReset(email, alphanumericCode, plaintextSecret, newPassword, clientId), initiateGitHubAuth, handleGitHubCallback, initiateGoogleAuth,