Skip to main content

Overview

Authentication server actions handle user registration, session management, and profile updates in VizBoard.

SignUp

Creates a new user account with email and password authentication.
export async function SignUp(data: signup): Promise<SignUpResponse>

Parameters

data
signup
required
User registration data
data.email
string
required
User’s email address (will be converted to lowercase)
data.password
string
required
User’s password (will be hashed with bcrypt)
data.firstName
string
required
User’s first name
data.lastName
string
required
User’s last name

Response

success
boolean
required
Indicates if the registration was successful
message
string
required
Success or error messagePossible messages:
  • "User registered successfully" - Registration succeeded
  • "This email is already registered." - Email already exists
  • "This email is already registered with Google or GitHub..." - OAuth conflict

Example

import { SignUp } from '@/app/actions/auth/signUp'

const result = await SignUp({
  email: '[email protected]',
  password: 'securePassword123',
  firstName: 'John',
  lastName: 'Doe'
})

if (result.success) {
  console.log('User registered successfully')
} else {
  console.error(result.message)
}

getUserByEmail

Retrieves a user by their email address.
export async function getUserByEmail(email: string): Promise<User | null>

Parameters

email
string
required
The email address to search for

Response

Returns a User object if found, or null if no user exists with that email.
id
string
Unique user identifier
email
string
User’s email address
firstName
string
User’s first name
lastName
string
User’s last name
password
string | null
Hashed password (null for OAuth users)

Example

import { getUserByEmail } from '@/app/actions/user/user'

const user = await getUserByEmail('[email protected]')

if (user) {
  console.log(`Found user: ${user.firstName} ${user.lastName}`)
}

getUserBySession

Retrieves the currently authenticated user from the session.
export async function getUserBySession(): Promise<UserSessionResponse>

Response

success
boolean
required
Indicates if the user was retrieved successfully
user
User
required
The authenticated user object (only present when success is true)
message
string
Error message (only present when success is false)Possible values:
  • "Not authenticated" - No active session
  • "Error fetching user" - Database error

Example

import { getUserBySession } from '@/app/actions/user/user'

const result = await getUserBySession()

if (result.success && result.user) {
  console.log(`Current user: ${result.user.name}`)
} else {
  console.error(result.message)
}

updateUserName

Updates the user’s first and last name.
export async function updateUserName(
  userId: string,
  data: { firstName: string; lastName: string }
): Promise<UpdateResponse>

Parameters

userId
string
required
The ID of the user to update
data
object
required
data.firstName
string
required
New first name
data.lastName
string
required
New last name

Response

success
boolean
required
Indicates if the update was successful
message
string
required
Success or error message

Example

import { updateUserName } from '@/app/actions/user/user'

const result = await updateUserName('clx1234567', {
  firstName: 'Jane',
  lastName: 'Smith'
})

if (result.success) {
  console.log('Name updated successfully')
}
This action automatically revalidates the /settings path.

updateUserEmail

Updates the user’s email address.
export async function updateUserEmail(
  userId: string,
  data: { email: string }
): Promise<UpdateResponse>

Parameters

userId
string
required
The ID of the user to update
data
object
required
data.email
string
required
New email address (will be converted to lowercase)

Response

success
boolean
required
Indicates if the update was successful
message
string
required
Success or error message

Example

import { updateUserEmail } from '@/app/actions/user/user'

const result = await updateUserEmail('clx1234567', {
  email: '[email protected]'
})

updateUserPassword

Updates the user’s password after verifying the current password.
export async function updateUserPassword(
  userId: string,
  userPassword: string | null,
  data: { currentPassword: string; newPassword: string }
): Promise<UpdateResponse>

Parameters

userId
string
required
The ID of the user to update
userPassword
string | null
required
The user’s current hashed password (null for OAuth users)
data
object
required
data.currentPassword
string
required
User’s current password (plaintext)
data.newPassword
string
required
New password (plaintext, will be hashed)

Response

success
boolean
required
Indicates if the update was successful
message
string
required
Success or error messagePossible messages:
  • "Password updated successfully"
  • "You are connected with a social account"
  • "Current password is not correct"
  • "New password must be different from current password"

Example

import { updateUserPassword } from '@/app/actions/user/user'

const result = await updateUserPassword(
  'clx1234567',
  user.password, // current hashed password from DB
  {
    currentPassword: 'oldPassword123',
    newPassword: 'newSecurePassword456'
  }
)

if (result.success) {
  console.log('Password updated')
} else {
  console.error(result.message)
}

deleteUserAccount

Permanently deletes a user account and clears their session.
export async function deleteUserAccount(userId: string): Promise<DeleteResponse>

Parameters

userId
string
required
The ID of the user to delete

Response

success
boolean
required
Indicates if the deletion was successful
message
string
required
Success or error message

Example

import { deleteUserAccount } from '@/app/actions/user/user'

const result = await deleteUserAccount('clx1234567')

if (result.success) {
  // Redirect to landing page
  redirect('/')
}
This action is irreversible and will delete all user data, including projects, connections, and widgets.

Type Definitions

interface signup {
  firstName: string
  lastName: string
  email: string
  password: string
}

interface SignUpResponse {
  success: boolean
  message: string
}

interface UserSessionResponse {
  success: boolean
  user?: User
  message?: string
}

interface UpdateResponse {
  success: boolean
  message: string
}

interface DeleteResponse {
  success: boolean
  message: string
}

Build docs developers (and LLMs) love