Skip to main content

Overview

The authentication module provides server actions for user authentication, profile management, and session handling using Supabase Auth. All functions in this module are Next.js Server Actions (marked with 'use server').

signIn

Authenticates a user with email and password.
async function signIn(formData: { 
  email: string; 
  password: string 
}): Promise<{ error?: string }>
formData
object
required
User credentials

Returns

error
string
Error message if authentication fails, undefined on success
On successful sign in, the user is automatically redirected to /dashboard/calendar

Example

import { signIn } from '@/lib/actions/auth'

const result = await signIn({
  email: '[email protected]',
  password: 'secure-password'
})

if (result?.error) {
  console.error('Login failed:', result.error)
}

signUp

Registers a new user account.
async function signUp(formData: { 
  email: string; 
  password: string; 
  nombre_completo: string 
}): Promise<{ error?: string }>
formData
object
required
New user registration data

Returns

error
string
Error message if registration fails, undefined on success
New users are automatically assigned the pendiente role and redirected to /dashboard/pendiente until an admin approves their account.

Example

import { signUp } from '@/lib/actions/auth'

const result = await signUp({
  email: '[email protected]',
  password: 'secure-password',
  nombre_completo: 'María González'
})

if (result?.error) {
  console.error('Registration failed:', result.error)
}

signOut

Ends the user’s session and signs them out.
async function signOut(): Promise<void>

Returns

Void. Redirects to /login after signing out.

Example

import { signOut } from '@/lib/actions/auth'

// Sign out the current user
await signOut()

getCurrentProfile

Retrieves the current authenticated user’s profile information.
async function getCurrentProfile(): Promise<Profile | null>

Returns

profile
Profile | null
The user’s profile object, or null if not authenticated

Example

import { getCurrentProfile } from '@/lib/actions/auth'

const profile = await getCurrentProfile()

if (!profile) {
  // User not authenticated
  return redirect('/login')
}

console.log('Current user:', profile.nombre_completo)
console.log('Role:', profile.rol)

Build docs developers (and LLMs) love