Fix password reset

This commit is contained in:
Stan Wohlwend 2024-07-28 06:09:56 -07:00
parent 51665a4162
commit f21e17114a
2 changed files with 7 additions and 4 deletions

View File

@ -71,7 +71,7 @@ export function createVerificationCodeHandler<
code: yupString().required(),
// we cast to undefined as a typehack because the types are a bit icky
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
}).concat((verifyOnly ? null : options.requestBody) as undefined ?? yupObject({})).required(),
}).concat((verifyOnly ? undefined : options.requestBody) ?? yupObject({})).required(),
}),
response: verifyOnly ? yupObject({
statusCode: yupNumber().oneOf([200]).required(),

View File

@ -445,16 +445,19 @@ export class StackClientInterface {
}
async resetPassword(
options: { code: string } & ({ password: string } | { onlyVerifyCode: boolean })
options: { code: string } & ({ password: string } | { onlyVerifyCode: true })
): Promise<KnownErrors["VerificationCodeError"] | undefined> {
const res = await this.sendClientRequestAndCatchKnownError(
"/auth/password/reset",
"onlyVerifyCode" in options ? "/auth/password/reset/check-code" : "/auth/password/reset",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(options),
body: JSON.stringify({
code: options.code,
...("password" in options ? { password: options.password } : {}),
}),
},
null,
[KnownErrors.VerificationCodeError]