Start working on Auth flow. Made email templates for auth
This commit is contained in:
@ -105,11 +105,21 @@ export const forgotPassword = async (formData: FormData) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const resetPassword = async (formData: FormData) => {
|
||||
const supabase = await createServerClient();
|
||||
const password = formData.get('password') as string;
|
||||
const confirmPassword = formData.get('confirmPassword') as string;
|
||||
|
||||
export const resetPassword = async (
|
||||
formData: FormData | {password: string, confirmPassword: string}
|
||||
) => {
|
||||
let password = '';
|
||||
let confirmPassword = '';
|
||||
|
||||
if (formData instanceof FormData) {
|
||||
password = formData.get('password') as string;
|
||||
confirmPassword = formData.get('confirmPassword') as string;
|
||||
} else {
|
||||
password = formData.password;
|
||||
confirmPassword = formData.confirmPassword;
|
||||
}
|
||||
|
||||
if (!password || !confirmPassword) {
|
||||
encodedRedirect(
|
||||
'error',
|
||||
@ -118,6 +128,39 @@ export const resetPassword = async (formData: FormData) => {
|
||||
);
|
||||
}
|
||||
|
||||
const supabase = await createServerClient();
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
encodedRedirect('error', '/reset-password', 'Passwords do not match');
|
||||
}
|
||||
|
||||
const { error } = await supabase.auth.updateUser({
|
||||
password: password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
encodedRedirect('error', '/reset-password', 'Password update failed');
|
||||
}
|
||||
|
||||
encodedRedirect('success', '/reset-password', 'Password updated');
|
||||
};
|
||||
|
||||
|
||||
export const resetPasswordFromEmail = async (formData: FormData) => {
|
||||
|
||||
const password = formData.get('password') as string;
|
||||
const confirmPassword = formData.get('confirmPassword') as string;
|
||||
|
||||
if (!password || !confirmPassword) {
|
||||
encodedRedirect(
|
||||
'error',
|
||||
'/reset-password',
|
||||
'Password and confirm password are required',
|
||||
);
|
||||
}
|
||||
|
||||
const supabase = await createServerClient();
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
encodedRedirect('error', '/reset-password', 'Passwords do not match');
|
||||
}
|
||||
|
Reference in New Issue
Block a user