Initialize the ServiceManager with Supabase configuration
ServiceManager configuration containing Supabase settings
Sign up a new user with email and password
User's email address
User's password
Optional
profile: Partial<Pick<User, "firstName" | "lastName" | "avatar">>Optional profile data to set during signup
Promise resolving to Result with user and verification status
const result = await serviceManager.signUp("user@example.com", "password123", {
firstName: "John",
lastName: "Doe"
});
if (result.success) {
if (result.data.needsVerification) {
console.log("Please check your email for verification");
}
console.log("User created:", result.data.user);
} else {
console.error("Sign up failed:", result.error.message);
}
Sign in an existing user with email and password
User's email address
User's password
Promise resolving to Result with user and session
const result = await serviceManager.signIn("user@example.com", "password123");
if (result.success) {
console.log("Signed in:", result.data.user);
console.log("Session expires at:", new Date(result.data.session.expiresAt));
} else {
console.error("Sign in failed:", result.error.message);
}
Sign out the current user
Promise resolving to Result indicating success or failure
const result = await serviceManager.signOut();
if (result.success) {
console.log("Successfully signed out");
} else {
console.error("Sign out failed:", result.error.message);
}
Resend email verification for the current user
Promise resolving to Result indicating success or failure
const result = await serviceManager.resendVerificationEmail();
if (result.success) {
console.log("Verification email sent");
} else {
console.error("Failed to send verification email:", result.error.message);
}
Update the current user's profile information
Profile fields to update (firstName, lastName, avatar)
Promise resolving to Result with updated user
const result = await serviceManager.updateProfile({
firstName: "John",
lastName: "Doe",
avatar: "https://example.com/avatar.jpg"
});
if (result.success) {
console.log("Profile updated:", result.data);
} else {
console.error("Profile update failed:", result.error.message);
}
Get the current authenticated user
Promise resolving to Result with current user or null
const result = await serviceManager.getCurrentUser();
if (result.success) {
if (result.data) {
console.log("Current user:", result.data);
} else {
console.log("No user is currently signed in");
}
} else {
console.error("Failed to get current user:", result.error.message);
}
Get the current authentication session
Promise resolving to Result with current session or null
const result = await serviceManager.getCurrentSession();
if (result.success) {
if (result.data) {
console.log("Current session:", result.data);
console.log("Expires at:", new Date(result.data.expiresAt));
} else {
console.log("No active session");
}
} else {
console.error("Failed to get current session:", result.error.message);
}
Create a new record in the specified table
Table name
Data to insert
Promise resolving to Result with created record
const result = await serviceManager.create("social_links", {
user_id: "user-id",
platform: "twitter",
url: "https://twitter.com/username"
});
if (result.success) {
console.log("Record created:", result.data);
} else {
console.error("Create failed:", result.error.message);
}
Read a record by ID from the specified table
Table name
Record ID
Promise resolving to Result with record or null
const result = await serviceManager.read("social_links", "link-id");
if (result.success) {
if (result.data) {
console.log("Record found:", result.data);
} else {
console.log("Record not found");
}
} else {
console.error("Read failed:", result.error.message);
}
Update a record by ID in the specified table
Table name
Record ID
Data to update
Promise resolving to Result with updated record
const result = await serviceManager.update("social_links", "link-id", {
url: "https://twitter.com/newusername"
});
if (result.success) {
console.log("Record updated:", result.data);
} else {
console.error("Update failed:", result.error.message);
}
Delete a record by ID from the specified table
Table name
Record ID
Promise resolving to Result indicating success or failure
const result = await serviceManager.delete("social_links", "link-id");
if (result.success) {
console.log("Record deleted successfully");
} else {
console.error("Delete failed:", result.error.message);
}
List records from the specified table with optional basic filtering
Table name
Optional
filters: Record<string, any>Optional filters to apply (key-value pairs for exact matches)
Promise resolving to Result with array of records
// List all records
const allResult = await serviceManager.list("social_links");
// List with filters
const filteredResult = await serviceManager.list("social_links", {
user_id: "user-id",
platform: "twitter"
});
if (filteredResult.success) {
console.log("Records found:", filteredResult.data);
} else {
console.error("List failed:", filteredResult.error.message);
}
Main ServiceManager class providing user authentication, profile management, and basic CRUD operations
Example