0.0.30 • Published 10 months ago

@tarobase/web v0.0.30

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@tarobase/web

Web SDK for Tarobase API - Browser/Frontend implementation. This package provides identical functionality to the original @tarobase/js-sdk package, but uses a modular architecture with shared functionality in @tarobase/core.

Installation

npm install @tarobase/web

Usage

import { init, login, getCurrentUser, set, get } from '@tarobase/web';

// Initialize the SDK
await init({
  appId: 'your-app-id',
  authMethod: 'phantom',  // or 'privy'
});

// Log in
await login();

// Get the current user
const user = getCurrentUser();
console.log(user.address);

// Set data
await set('todos/123', { text: 'Buy milk', completed: false });

// Get data
const todo = await get('todos/123');
console.log(todo);

React Hook

import { useAuth } from '@tarobase/web';

function MyComponent() {
  const { user, isLoading, isLoggedIn, login, logout } = useAuth();

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (!isLoggedIn) {
    return <button onClick={login}>Login</button>;
  }

  return (
    <div>
      <p>Logged in as: {user.address}</p>
      <button onClick={logout}>Logout</button>
    </div>
  );
}

Authentication Methods

Phantom Wallet

await init({
  appId: 'your-app-id',
  authMethod: 'phantom'
});

Privy Wallet

await init({
  appId: 'your-app-id',
  authMethod: 'privy',
  privyConfig: {
    appId: 'your-privy-app-id',
    config: {
      // Privy configuration options
      embeddedWallets: {
        solana: {
          createOnLogin: "users-without-wallets"
        }
      }
    }
  }
});

API Reference

Initialization

function init(newConfig: Partial<ClientConfig>): Promise<void>;

Authentication

function login(): Promise<User | null>;
function logout(): Promise<void>;
function getCurrentUser(): User | null;
function onAuthStateChanged(callback: (user: User | null) => void): void;

Data Operations

function get(path: string): Promise<any>;
function set(path: string, data: any, options?: SetOptions): Promise<any>;
function setMany(paths: { [key: string]: any }, options?: SetOptions): Promise<any>;
function setFile(path: string, file: File, metadata?: any): Promise<any>;
function getFiles(path: string): Promise<any>;
function runQuery(queryString: string, variables?: any): Promise<any>;
function runQueryMany(queryString: string, variables?: any): Promise<any>;

Subscriptions

function subscribe(path: string, options?: SubscriptionOptions): Promise<() => void>;

Contributing

Please see the main repository for contribution guidelines.

0.0.30

10 months ago

0.0.29

10 months ago

0.0.28

10 months ago

0.0.27

10 months ago

0.0.26

10 months ago

0.0.25

10 months ago

0.0.24

10 months ago

0.0.23

10 months ago

0.0.22

10 months ago

0.0.21

10 months ago

0.0.20

10 months ago

0.0.19

10 months ago

0.0.18

10 months ago

0.0.17

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago