feat: add reset password functionality

This commit is contained in:
Aaron William Po
2023-11-23 20:59:46 -05:00
parent fae0b0793d
commit c3a991f938
17 changed files with 475 additions and 464 deletions

View File

@@ -0,0 +1,24 @@
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
const sendForgotPasswordRequest = async (email: string) => {
const response = await fetch('/api/users/forgot-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
});
if (!response.ok) {
throw new Error("Something went wrong and we couldn't send the reset link.");
}
const json = await response.json();
const parsed = APIResponseValidationSchema.safeParse(json);
if (!parsed.success) {
throw new Error(parsed.error.message);
}
return parsed.data;
};
export default sendForgotPasswordRequest;