mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
feat: add reset password functionality
This commit is contained in:
24
src/requests/User/sendForgotPasswordRequest.tsx
Normal file
24
src/requests/User/sendForgotPasswordRequest.tsx
Normal 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;
|
||||
Reference in New Issue
Block a user