We finally fixed the sign in and sign out stuff with our client components not updating
This commit is contained in:
@ -7,7 +7,6 @@ import { headers } from 'next/headers';
|
||||
import { redirect } from 'next/navigation';
|
||||
import type { User } from '@/utils/supabase';
|
||||
import type { Result } from './index';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
export const signUp = async (formData: FormData) => {
|
||||
const name = formData.get('name') as string;
|
||||
@ -47,7 +46,9 @@ export const signUp = async (formData: FormData) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const signIn = async (formData: FormData) => {
|
||||
export const signIn = async (
|
||||
formData: FormData,
|
||||
): Promise<Result<null>> => {
|
||||
const email = formData.get('email') as string;
|
||||
const password = formData.get('password') as string;
|
||||
const supabase = await createServerClient();
|
||||
@ -56,11 +57,10 @@ export const signIn = async (formData: FormData) => {
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return encodedRedirect('error', '/sign-in', error.message);
|
||||
return { success: false, error: error.message };
|
||||
} else {
|
||||
return redirect('/');
|
||||
return { success: true, data: null };
|
||||
}
|
||||
};
|
||||
|
||||
@ -98,43 +98,27 @@ export const forgotPassword = async (formData: FormData) => {
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export const resetPassword = async ({
|
||||
password,
|
||||
confirmPassword,
|
||||
}: {
|
||||
password: string,
|
||||
confirmPassword: string
|
||||
}): Promise<Result<null>> => {
|
||||
if (!password || !confirmPassword) {
|
||||
encodedRedirect(
|
||||
'error',
|
||||
'/reset-password',
|
||||
'Password and confirm password are required',
|
||||
);
|
||||
return { success: false, error: 'Password and confirm password are required!' };
|
||||
}
|
||||
|
||||
const supabase = await createServerClient();
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
encodedRedirect('error', '/reset-password', 'Passwords do not match');
|
||||
return { success: false, error: 'Passwords do not match!' };
|
||||
}
|
||||
|
||||
const { error } = await supabase.auth.updateUser({
|
||||
password: password,
|
||||
password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
encodedRedirect('error', '/reset-password', 'Password update failed');
|
||||
return { success: false, error: `Password update failed: ${error.message}` };
|
||||
}
|
||||
|
||||
encodedRedirect('success', '/reset-password', 'Password updated');
|
||||
return { success: true, data: null };
|
||||
};
|
||||
|
||||
|
||||
@ -165,10 +149,11 @@ export const resetPasswordFromEmail = async (formData: FormData) => {
|
||||
encodedRedirect('success', '/reset-password', 'Password updated');
|
||||
};
|
||||
|
||||
export const signOut = async () => {
|
||||
export const signOut = async (): Promise<Result<null>> => {
|
||||
const supabase = await createServerClient();
|
||||
await supabase.auth.signOut();
|
||||
return redirect('/sign-in');
|
||||
const { error } = await supabase.auth.signOut();
|
||||
if (error) return { success: false, error: error.message }
|
||||
return { success: true, data: null };
|
||||
};
|
||||
|
||||
export const getUser = async (): Promise<Result<User>> => {
|
||||
|
Reference in New Issue
Block a user