solobase-js
Version:
A 100% drop-in replacement for the Supabase JavaScript client. Self-hosted Supabase alternative with complete API compatibility.
285 lines • 7.21 kB
TypeScript
import { SolobaseFetch } from './lib/fetch.js';
import { AuthUser, Session, AuthResponse, AuthError, SolobaseClientOptions } from './types/index.js';
import { CookieManager } from './lib/CookieManager.js';
export interface SignUpWithPasswordCredentials {
email: string;
password: string;
options?: {
data?: object;
captchaToken?: string;
emailRedirectTo?: string;
};
}
export interface SignInWithPasswordCredentials {
email: string;
password: string;
options?: {
captchaToken?: string;
};
}
export interface SignInWithOAuthCredentials {
provider: 'google' | 'github' | 'facebook' | 'apple' | 'discord' | 'twitter';
options?: {
redirectTo?: string;
scopes?: string;
queryParams?: {
[key: string]: string;
};
skipBrowserRedirect?: boolean;
};
}
export interface ResetPasswordForEmailOptions {
email: string;
options?: {
captchaToken?: string;
redirectTo?: string;
};
}
export interface VerifyOtpOptions {
token_hash: string;
type: 'signup' | 'invite' | 'recovery' | 'email_change' | 'phone_change';
email?: string;
phone?: string;
}
export interface VerifyEmailOptions {
token: string;
}
export interface ResendVerificationOptions {
email: string;
}
export interface UpdateUserOptions {
email?: string;
password?: string;
data?: object;
}
export interface AdminCreateUserOptions {
email: string;
password: string;
email_confirm?: boolean;
phone_confirm?: boolean;
user_metadata?: object;
app_metadata?: object;
}
export interface AdminUpdateUserOptions {
email?: string;
password?: string;
email_confirm?: boolean;
phone_confirm?: boolean;
user_metadata?: object;
app_metadata?: object;
ban_duration?: string;
}
export interface AdminListUsersOptions {
page?: number;
per_page?: number;
}
export declare class SolobaseAuthClient {
private fetch;
private currentSession;
private currentUser;
private refreshToken;
private refreshTimer;
private autoRefreshToken;
private persistSession;
private cookieManager;
private onAuthStateChangeCallbacks;
constructor(fetch: SolobaseFetch, options?: SolobaseClientOptions['auth'], cookieManager?: CookieManager);
/**
* Creates a new user with email and password
*/
signUp(credentials: SignUpWithPasswordCredentials): Promise<AuthResponse>;
/**
* Log in an existing user with email and password
*/
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<AuthResponse>;
/**
* Log in with OAuth provider
*/
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<{
data: {
url: string;
};
error: null;
} | {
data: null;
error: AuthError;
}>;
/**
* Log out the current user
*/
signOut(): Promise<{
error: AuthError | null;
}>;
/**
* Get the current user
*/
getUser(): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
/**
* Get the current session
*/
getSession(): Promise<{
data: {
session: Session | null;
};
error: AuthError | null;
}>;
/**
* Update user information
*/
updateUser(options: UpdateUserOptions): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
/**
* Send password reset email
*/
resetPasswordForEmail(options: ResetPasswordForEmailOptions): Promise<{
data: {};
error: AuthError | null;
}>;
/**
* Verify OTP token (for password reset, email confirmation, etc.)
*/
verifyOtp(options: VerifyOtpOptions): Promise<AuthResponse>;
/**
* Verify email address with token
*/
verifyEmail(options: VerifyEmailOptions): Promise<AuthResponse>;
/**
* Resend email verification
*/
resendVerification(options: ResendVerificationOptions): Promise<{
data: {
message?: string;
};
error: AuthError | null;
}>;
/**
* Refresh the current session
*/
refreshSession(): Promise<{
data: {
session: Session | null;
};
error: AuthError | null;
}>;
/**
* Listen to auth state changes
*/
onAuthStateChange(callback: (event: 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED', session: Session | null) => void): {
data: {
subscription: {
unsubscribe: () => void;
};
};
};
/**
* Admin functionality
*/
get admin(): SolobaseAuthAdminClient;
/**
* Set session and start auto-refresh if enabled
*/
private setSession;
/**
* Clear current session
*/
private clearSession;
/**
* Load saved session from storage or cookies
*/
private loadSession;
/**
* Setup automatic token refresh
*/
private setupRefreshTimer;
}
/**
* Admin client for managing users and authentication
*/
export declare class SolobaseAuthAdminClient {
private fetch;
constructor(fetch: SolobaseFetch);
/**
* Create a new user (admin only)
*/
createUser(options: AdminCreateUserOptions): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
/**
* Update a user (admin only)
*/
updateUserById(userId: string, options: AdminUpdateUserOptions): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
/**
* Delete a user (admin only)
*/
deleteUser(userId: string): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
/**
* Get a user by ID (admin only)
*/
getUserById(userId: string): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
/**
* List users (admin only)
*/
listUsers(options?: AdminListUsersOptions): Promise<{
data: {
users: AuthUser[];
count?: number;
};
error: AuthError | null;
}>;
/**
* Generate a password reset link for a user (admin only)
*/
generateLink(options: {
type: 'signup' | 'invite' | 'recovery' | 'email_change_current' | 'email_change_new';
email: string;
password?: string;
data?: object;
redirect_to?: string;
}): Promise<{
data: {
user: AuthUser | null;
properties?: any;
};
error: AuthError | null;
}>;
/**
* Invite a user by email (admin only)
*/
inviteUserByEmail(email: string, options?: {
data?: object;
redirect_to?: string;
}): Promise<{
data: {
user: AuthUser | null;
};
error: AuthError | null;
}>;
}
//# sourceMappingURL=SolobaseAuthClient.d.ts.map