Cleanup. Stuff from yesterday idk

This commit is contained in:
2025-06-06 08:43:18 -05:00
parent a776c5a30a
commit 35e019558f
29 changed files with 866 additions and 694 deletions

View File

@ -1,13 +1,14 @@
'use server';
import 'server-only';
import { encodedRedirect } from '@/utils/utils';
import { createServerClient } from '@/utils/supabase';
import { headers } from 'next/headers';
import type { User } from '@/utils/supabase';
import type { Result } from './index';
import type { Result } from '.';
export const signUp = async (formData: FormData): Promise<Result<string | null>> => {
export const signUp = async (
formData: FormData,
): Promise<Result<string | null>> => {
const name = formData.get('name') as string;
const email = formData.get('email') as string;
const password = formData.get('password') as string;
@ -15,11 +16,7 @@ export const signUp = async (formData: FormData): Promise<Result<string | null>>
const origin = (await headers()).get('origin');
if (!email || !password) {
return encodedRedirect(
'error',
'/sign-up',
'Email & password are required',
);
return { success: false, error: 'Email and password are required' };
}
const { error } = await supabase.auth.signUp({
@ -34,6 +31,7 @@ export const signUp = async (formData: FormData): Promise<Result<string | null>>
},
},
});
if (error) {
return { success: false, error: error.message };
} else {
@ -44,9 +42,7 @@ export const signUp = async (formData: FormData): Promise<Result<string | null>>
}
};
export const signIn = async (
formData: FormData,
): Promise<Result<null>> => {
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();
@ -68,10 +64,10 @@ export const signInWithMicrosoft = async (): Promise<Result<string>> => {
provider: 'azure',
options: {
scopes: 'openid, profile email offline_access',
}
},
});
if (error) return { success: false, error: error.message };
return { success: true, data: data.url};
return { success: true, data: data.url };
};
export const signInWithApple = async (): Promise<Result<string>> => {
@ -80,13 +76,15 @@ export const signInWithApple = async (): Promise<Result<string>> => {
provider: 'apple',
options: {
scopes: 'openid, profile email offline_access',
}
},
});
if (error) return { success: false, error: error.message };
return { success: true, data: data.url};
return { success: true, data: data.url };
};
export const forgotPassword = async (formData: FormData): Promise<Result<string | null>> => {
export const forgotPassword = async (
formData: FormData,
): Promise<Result<string | null>> => {
const email = formData.get('email') as string;
const supabase = await createServerClient();
const origin = (await headers()).get('origin');
@ -102,15 +100,22 @@ export const forgotPassword = async (formData: FormData): Promise<Result<string
if (error) {
return { success: false, error: 'Could not reset password' };
}
return { success: true, data: 'Check your email for a link to reset your password.' };
return {
success: true,
data: 'Check your email for a link to reset your password.',
};
};
export const resetPassword = async (formData: FormData): Promise<Result<null>> => {
export const resetPassword = async (
formData: FormData,
): Promise<Result<null>> => {
const password = formData.get('password') as string;
const confirmPassword = formData.get('confirmPassword') as string;
if (!password || !confirmPassword) {
return { success: false, error: 'Password and confirm password are required!' };
return {
success: false,
error: 'Password and confirm password are required!',
};
}
const supabase = await createServerClient();
if (password !== confirmPassword) {
@ -120,7 +125,10 @@ export const resetPassword = async (formData: FormData): Promise<Result<null>> =
password,
});
if (error) {
return { success: false, error: `Password update failed: ${error.message}` };
return {
success: false,
error: `Password update failed: ${error.message}`,
};
}
return { success: true, data: null };
};
@ -128,7 +136,7 @@ export const resetPassword = async (formData: FormData): Promise<Result<null>> =
export const signOut = async (): Promise<Result<null>> => {
const supabase = await createServerClient();
const { error } = await supabase.auth.signOut();
if (error) return { success: false, error: error.message }
if (error) return { success: false, error: error.message };
return { success: true, data: null };
};