Skip to content

Commit

Permalink
Add client_id to reset pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Feb 20, 2025
1 parent fb320d0 commit 7c69cbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ export async function changePassword(currentPassword: string, newPassword: strin
);
}

export async function initiateGitHubAuth(inviteCode?: string): Promise<GithubAuthResponse> {
export async function initiateGitHubAuth(client_id: string, inviteCode?: string): Promise<GithubAuthResponse> {
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"
);
Expand Down Expand Up @@ -355,12 +355,12 @@ export type GoogleAuthResponse = {
csrf_token: string;
};

export async function initiateGoogleAuth(inviteCode?: string): Promise<GoogleAuthResponse> {
export async function initiateGoogleAuth(client_id: string, inviteCode?: string): Promise<GoogleAuthResponse> {
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"
);
Expand Down
27 changes: 19 additions & 8 deletions src/lib/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,13 @@ export type OpenSecretContextType = {
refetchUser: () => Promise<void>;
changePassword: typeof api.changePassword;
refreshAccessToken: typeof api.refreshToken;
requestPasswordReset: typeof api.requestPasswordReset;
confirmPasswordReset: typeof api.confirmPasswordReset;
requestPasswordReset: (email: string, hashedSecret: string) => Promise<void>;
confirmPasswordReset: (
email: string,
alphanumericCode: string,
plaintextSecret: string,
newPassword: string
) => Promise<void>;
initiateGitHubAuth: (inviteCode: string) => Promise<api.GithubAuthResponse>;
handleGitHubCallback: (code: string, state: string, inviteCode: string) => Promise<void>;
initiateGoogleAuth: (inviteCode: string) => Promise<api.GoogleAuthResponse>;
Expand Down Expand Up @@ -360,8 +365,8 @@ export const OpenSecretContext = createContext<OpenSecretContextType>({
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: "" }),
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7c69cbf

Please sign in to comment.