Skip to main content
All functions are in src/services/auth.service.ts. The service uses the Supabase Auth client for session management and the customer_profiles table for extended profile data.

Key behaviors

  • signUp auto-creates a profile — immediately after Supabase Auth creates the user, createCustomerProfile is called with an upsert to populate customer_profiles. Profile creation errors are swallowed so they never block signup.
  • All date fields are ISO 8601 strings.
  • resetPassword and signUp both use window.location.origin as the redirect base, so they require a browser context.

signUp()

export async function signUp(
    email: string,
    password: string,
    fullName?: string,
    phone?: string,
    ai_preferences?: AIPreferences,
    ia_context?: IAContext
): Promise<{ user: User | null; session: Session | null }>
Registers a new user with Supabase Auth and creates their customer_profiles row in one call.
email
string
required
User’s email address.
password
string
required
Password (min 6 characters enforced by Supabase).
fullName
string
Optional display name stored in customer_profiles.full_name.
phone
string
Phone number stored in both phone and whatsapp columns initially.
ai_preferences
AIPreferences
Optional AI personalisation preferences.
ia_context
IAContext
Optional IA context object for the AI concierge.
data
object
Supabase Auth response containing user and session.
import { signUp } from '@/services';

const data = await signUp(
    '[email protected]',
    'securepassword',
    'John Doe',
    '+522281234567'
);
// data.user.id is the UUID used everywhere else

signIn()

export async function signIn(
    email: string,
    password: string
): Promise<{ user: User; session: Session }>
Authenticates via signInWithPassword. Throws the Supabase error on failure.
const { user, session } = await signIn('[email protected]', 'password');

signOut()

export async function signOut(): Promise<void>
Clears the Supabase session. Throws on error.
await signOut();

resetPassword()

export async function resetPassword(
    email: string
): Promise<void>
Sends a password-reset email via resetPasswordForEmail. Redirects to {origin}/login after the user clicks the link.
email
string
required
Email address to send the reset link to.
await resetPassword('[email protected]');

getCurrentUser()

export async function getCurrentUser(): Promise<User | null>
Calls supabase.auth.getUser(). Returns null if no authenticated session exists.
const user = await getCurrentUser();
if (user) {
    console.log(user.id);
}

getCustomerProfile()

export async function getCustomerProfile(
    userId: string
): Promise<CustomerProfile | null>
Fetches the full customer_profiles row for a user. Uses maybeSingle() so it returns null instead of an error when the profile doesn’t exist yet.
userId
string
required
The auth.users.id UUID.
CustomerProfile | null
CustomerProfile | null
The extended profile, or null if not found.
const profile = await getCustomerProfile(user.id);
if (profile) {
    console.log(profile.tier); // 'bronze' | 'silver' | 'gold' | 'platinum'
}

createCustomerProfile()

export async function createCustomerProfile(
    userId: string,
    data: {
        full_name?: string | null;
        phone: string | null;
        whatsapp: string | null;
        ai_preferences?: AIPreferences;
        ia_context?: IAContext;
    }
): Promise<void>
Upserts a row into customer_profiles. Called automatically by signUp but can also be called manually when a user profile needs to be force-created. Errors are not thrown — they are logged to console.error.
await createCustomerProfile('user-uuid', {
    full_name: 'Jane Doe',
    phone: '+522281234567',
    whatsapp: '+522281234567',
});

updateProfile()

export async function updateProfile(
    userId: string,
    data: {
        full_name?: string;
        phone?: string;
        whatsapp?: string;
        birthdate?: string;
        avatar_url?: string;
        ia_context?: IAContext;
    }
): Promise<void>
Upserts partial data into customer_profiles. Throws on Supabase error.
userId
string
required
The auth.users.id UUID.
data
object
required
Partial profile fields to update.
await updateProfile(user.id, {
    full_name: 'Jane Smith',
    birthdate: '1995-06-15',
});

Usage with AuthContext

In practice, components use the useAuth() hook which reads from AuthContext rather than calling these service functions directly. The context provides user, profile, loading, and signIn, signUp, signOut wrappers.
import { useAuth } from '@/hooks/useAuth';

function MyComponent() {
    const { user, profile, signIn, signOut } = useAuth();
    // ...
}

Build docs developers (and LLMs) love