0.0.30 • Published 2 months ago

@tarobase/web v0.0.30

Weekly downloads
-
License
MIT
Repository
-
Last release
2 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

2 months ago

0.0.29

2 months ago

0.0.28

2 months ago

0.0.27

2 months ago

0.0.26

2 months ago

0.0.25

2 months ago

0.0.24

2 months ago

0.0.23

2 months ago

0.0.22

2 months ago

0.0.21

2 months ago

0.0.20

2 months ago

0.0.19

2 months ago

0.0.18

2 months ago

0.0.17

2 months ago

0.0.16

2 months ago

0.0.15

2 months ago

0.0.14

2 months ago

0.0.12

2 months ago

0.0.11

2 months ago

0.0.10

2 months ago

0.0.9

2 months ago

0.0.8

2 months ago

0.0.7

2 months ago

0.0.5

2 months ago

0.0.4

2 months ago

0.0.3

2 months ago

0.0.2

2 months ago

0.0.1

2 months ago