36 lines
1.4 KiB
Dart
36 lines
1.4 KiB
Dart
import 'package:pocketbase/pocketbase.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
/// Connexion au backend PocketBase (auto-hébergé sur le Raspberry Pi).
|
|
class PocketBaseConfig {
|
|
PocketBaseConfig._();
|
|
|
|
/// URL du serveur PocketBase, exposé publiquement en HTTPS via Tailscale
|
|
/// Funnel (sur le Raspberry). Accessible de partout (4G, autre WiFi…).
|
|
/// Accès local direct (dans le bar) possible via http://192.168.1.32:8090
|
|
/// mais on garde l'URL publique partout pour que ça marche en tout lieu.
|
|
static const String url = 'https://db.tailb756e1.ts.net';
|
|
|
|
static const _cleAuth = 'pb_auth';
|
|
}
|
|
|
|
/// Client PocketBase global (initialisé par [initPocketBase]).
|
|
late final PocketBase pb;
|
|
|
|
/// Initialise le client PocketBase avec une session persistée (SharedPreferences),
|
|
/// pour rester connecté d'une ouverture de l'app à l'autre.
|
|
Future<void> initPocketBase() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final store = AsyncAuthStore(
|
|
save: (data) async => prefs.setString(PocketBaseConfig._cleAuth, data),
|
|
initial: prefs.getString(PocketBaseConfig._cleAuth),
|
|
clear: () async => prefs.remove(PocketBaseConfig._cleAuth),
|
|
);
|
|
pb = PocketBase(PocketBaseConfig.url, authStore: store);
|
|
}
|
|
|
|
/// Vrai si l'utilisateur connecté fait partie du personnel du magasin.
|
|
bool get estStaff =>
|
|
pb.authStore.isValid &&
|
|
(pb.authStore.record?.getBoolValue('is_staff') ?? false);
|