phatsa

Dart and Flutter client for Phatsa: app user auth, plugin tables, and RPC over the REST API. The Dart counterpart of @phatsa/client.

Install

dart pub add phatsa

Usage

import 'package:phatsa/phatsa.dart';

final phatsa = PhatsaClient('https://your-project.phatsa.com', key: 'pk_...');

await phatsa.auth.signIn(email: 'user@example.com', password: 'secret');

final threads = await phatsa
    .from('forum', 'forum_threads')
    .select('id,title')
    .eq('status', 'open')
    .order('created_at', ascending: false)
    .limit(20)
    .fetch();

await phatsa.from('forum', 'forum_threads').update(id, {'title': 'New title'});
await phatsa.rpc('forum', 'lock_thread', {'thread_id': id, 'locked': true});

Failed calls throw PhatsaException with status, code and message; network_error (status 0) means the panel was unreachable.

Keys

  • pk_ (publishable): for apps. It grants nothing alone; the signed-in user and the plugin's row rules decide access.
  • sk_ (secret): server only. Never ship it in an app.

Keeping the session

By default the session lives in memory and ends with the app. On mobile, keep it in secure storage by implementing SessionStorage. For example, with flutter_secure_storage:

class SecureSessionStorage implements SessionStorage {
  const SecureSessionStorage(this._storage);

  final FlutterSecureStorage _storage;

  @override
  Future<String?> getItem(String key) => _storage.read(key: key);

  @override
  Future<void> setItem(String key, String value) => _storage.write(key: key, value: value);

  @override
  Future<void> removeItem(String key) => _storage.delete(key: key);
}

Tokens refresh automatically, and phatsa.auth.onAuthStateChange reports sign-in, sign-out and refresh.

Not yet included

File storage, realtime channels, payments, and sign-in with the hosted account page.

Libraries

phatsa
Phatsa client for Dart and Flutter.