UNPKG

supabase-node-kit

Version:

A backend utility package for Supabase authentication and database functionality.

170 lines (165 loc) 6.83 kB
import * as _supabase_supabase_js from '@supabase/supabase-js'; import { Provider, Session } from '@supabase/supabase-js'; declare const authService: { /** * Authenticates a user with email and password * @param email - User's email address * @param password - User's password * @returns Promise containing the sign in response * @example * const { data, error } = await authService.signIn('user@example.com', 'password123') */ signIn(email: string, password: string): Promise<_supabase_supabase_js.AuthTokenResponsePassword>; /** * Signs out the currently authenticated user * @returns Promise containing the sign out response * @example * await authService.signOutCurrentUser() */ signOutCurrentUser(): Promise<{ error: _supabase_supabase_js.AuthError | null; }>; /** * Retrieves the currently authenticated user's details * @returns Promise containing the current user data * @example * const { data: { user }, error } = await authService.getCurrentUser() */ getCurrentUser(): Promise<_supabase_supabase_js.UserResponse>; signUp(email: string, password: string): Promise<_supabase_supabase_js.AuthResponse>; /** * Signs in with a third-party provider * @param provider - The authentication provider (google, github, etc.) * @returns Promise containing the sign in response * @example * await authService.signInWithProvider('google') */ signInWithProvider(provider: Provider): Promise<_supabase_supabase_js.OAuthResponse>; /** * Sends a password reset email * @param email - User's email address * @returns Promise containing the reset response * @example * const { data, error } = await authService.resetPassword('user@example.com') */ resetPassword(email: string): Promise<{ data: {}; error: null; } | { data: null; error: _supabase_supabase_js.AuthError; }>; /** * Updates user's password * @param newPassword - New password * @returns Promise containing the update response * @example * const { data, error } = await authService.updatePassword('newPassword123') */ updatePassword(newPassword: string): Promise<_supabase_supabase_js.UserResponse>; }; declare const authAdminService: { /** * Creates a new user account (Server-side only) * @param email - New user's email address * @param password - New user's password * @returns Promise containing the created user data * @throws Error if called from client-side * @example * // Only in API routes or server-side code * const { data, error } = await authAdminService.createUser('newuser@example.com', 'password123') */ createUser(email: string, password: string): Promise<_supabase_supabase_js.UserResponse>; /** * Deletes a user account by ID (Server-side only) * @param userId - The UUID of the user to delete * @returns Promise containing the deletion response * @throws Error if called from client-side * @example * // Only in API routes or server-side code * await authAdminService.deleteUser('user-uuid-here') */ deleteUser(userId: string): Promise<_supabase_supabase_js.UserResponse>; /** * Retrieves user details by ID (Server-side only) * @param userId - The UUID of the user to fetch * @returns Promise containing the user data * @throws Error if called from client-side * @example * // Only in API routes or server-side code * const { data: { user }, error } = await authAdminService.getUserById('user-uuid-here') */ getUserById(userId: string): Promise<_supabase_supabase_js.UserResponse>; /** * Forces sign out for a specific user (Server-side only) * @param userId - The UUID of the user to sign out * @returns Promise containing the sign out response * @throws Error if called from client-side * @example * // Only in API routes or server-side code * await authAdminService.signOutUser('user-uuid-here') */ signOutUser(userId: string): Promise<{ data: null; error: _supabase_supabase_js.AuthError | null; }>; checkUserExists(email: string): Promise<{ exists: boolean; error: _supabase_supabase_js.PostgrestError | null; }>; /** * Updates user's email verification status (Server-side only) * @param userId - The UUID of the user * @param verified - Boolean indicating verification status * @throws Error if called from client-side * @example * await authAdminService.updateEmailVerification('user-uuid', true) */ updateEmailVerification(userId: string, verified: boolean): Promise<_supabase_supabase_js.UserResponse>; /** * Initialize auth session from existing session data * @returns Promise containing the session data * @example * const { data: { session }, error } = await authService.initializeSession() */ initializeSession(): Promise<{ data: { session: Session; }; error: null; } | { data: { session: null; }; error: _supabase_supabase_js.AuthError; } | { data: { session: null; }; error: null; }>; /** * Set up an auth state change listener * @param callback - Function to handle auth state changes * @returns Cleanup function to remove the listener * @example * const unsubscribe = authService.onAuthStateChange((event, session) => { * console.log('Auth event:', event, session) * }) */ onAuthStateChange(callback: (event: string, session: Session | null) => void): { data: { subscription: _supabase_supabase_js.Subscription; }; }; }; declare const dbService: { getAll(table: string, useAdmin?: boolean): Promise<_supabase_supabase_js.PostgrestSingleResponse<any[]>>; getById(table: string, id: number, useAdmin?: boolean): Promise<_supabase_supabase_js.PostgrestSingleResponse<any>>; insert(table: string, values: object, useAdmin?: boolean): Promise<_supabase_supabase_js.PostgrestSingleResponse<null>>; update(table: string, id: number, values: object, useAdmin?: boolean): Promise<_supabase_supabase_js.PostgrestSingleResponse<null>>; remove(table: string, id: number, useAdmin?: boolean): Promise<_supabase_supabase_js.PostgrestSingleResponse<null>>; }; declare const supabaseClient: _supabase_supabase_js.SupabaseClient<any, "public", any>; declare const supabaseAdmin: _supabase_supabase_js.SupabaseClient<any, "public", any> | null; export { authAdminService, authService, dbService, supabaseAdmin, supabaseClient };