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 }>
Returns
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 }>
New user registration data
Returns
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
The user’s profile object, or null if not authenticated User’s role: admin, coordinadora, laboratorio, cedis, pendiente, or consulta
ISO timestamp of profile creation
ISO timestamp of last profile update
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 )