(Feat) Migration PocketBase

This commit is contained in:
2026-07-18 11:51:32 +02:00
parent 1d3ee69c6d
commit e483fd9070
15 changed files with 522 additions and 453 deletions
+13 -11
View File
@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:pocketbase/pocketbase.dart';
import '../supabase_config.dart';
import '../pocketbase_config.dart';
import '../theme.dart';
/// Connexion du personnel du magasin (staff). Les comptes staff sont créés dans
/// Supabase (voir SETUP.md) — pas d'inscription libre ici.
/// PocketBase (champ is_staff = true) — pas d'inscription libre ici.
class StaffLoginScreen extends StatefulWidget {
const StaffLoginScreen({super.key});
@@ -35,22 +35,24 @@ class _StaffLoginScreenState extends State<StaffLoginScreen> {
_erreur = null;
});
try {
await supabase.auth.signInWithPassword(
email: _emailCtrl.text.trim(),
password: _mdpCtrl.text,
);
await pb.collection('users').authWithPassword(
_emailCtrl.text.trim(),
_mdpCtrl.text,
);
// Vérifie que ce compte est bien autorisé (staff).
final estStaff = await supabase.rpc('est_staff') as bool? ?? false;
if (!estStaff) {
await supabase.auth.signOut();
pb.authStore.clear();
if (mounted) {
setState(() => _erreur =
'Ce compte n\'est pas autorisé pour la tablette (staff).');
}
}
// Si staff : l'AuthGate bascule automatiquement vers l'app.
} on AuthException catch (e) {
if (mounted) setState(() => _erreur = e.message);
} on ClientException catch (e) {
if (mounted) {
setState(() => _erreur = 'Identifiants incorrects');
}
debugPrint('Login error: ${e.response}');
} catch (e) {
if (mounted) setState(() => _erreur = 'Erreur : $e');
} finally {