bLOQUE p1 BACKEND Y SEGURIDAD, AUTENTICACION CON SUPABASE. jwt. RBAC CRUD

This commit is contained in:
shinra32
2026-05-22 19:45:05 -06:00
parent 5dc8390855
commit fc28333e3f
52 changed files with 1605 additions and 109 deletions

View File

View File

@@ -0,0 +1,22 @@
import 'colonia.dart';
class AddressModel {
const AddressModel({
required this.label,
required this.street,
required this.colonia,
});
final String label;
final String street;
final Colonia colonia;
Map<String, dynamic> toJson() {
return <String, dynamic>{
'label': label,
'calle': street,
'colonia': colonia.nombre,
'route_id': colonia.routeId,
};
}
}

View File

@@ -0,0 +1,11 @@
class AuthSession {
const AuthSession({required this.token, this.userRole, this.routeId});
final String token;
final String? userRole;
final String? routeId;
bool get isCitizen => userRole == 'citizen';
bool get isDriver => userRole == 'driver';
bool get isAdmin => userRole == 'admin';
}

View File

@@ -0,0 +1,28 @@
class AuthState {
const AuthState({
required this.isAuthenticated,
this.token,
this.userRole,
this.routeId,
});
const AuthState.unauthenticated()
: isAuthenticated = false,
token = null,
userRole = null,
routeId = null;
const AuthState.authenticated({
required String token,
String? userRole,
String? routeId,
}) : isAuthenticated = true,
token = token,
userRole = userRole,
routeId = routeId;
final bool isAuthenticated;
final String? token;
final String? userRole;
final String? routeId;
}

View File

@@ -0,0 +1,37 @@
class Colonia {
const Colonia({
required this.id,
required this.nombre,
this.routeId,
this.horarioEstimado,
this.turno,
});
final String id;
final String nombre;
final String? routeId;
final String? horarioEstimado;
final String? turno;
factory Colonia.fromJson(Map<String, dynamic> json) {
final rawId =
json['id'] ??
json['routeId'] ??
json['route_id'] ??
json['nombre'] ??
json['name'];
final rawNombre = json['nombre'] ?? json['name'] ?? rawId;
return Colonia(
id: rawId?.toString() ?? rawNombre?.toString() ?? '',
nombre: rawNombre?.toString() ?? '',
routeId: (json['routeId'] ?? json['route_id'])?.toString(),
horarioEstimado:
(json['horario_estimado'] ??
json['horarioEstimado'] ??
json['schedule'])
?.toString(),
turno: (json['turno'] ?? json['shift'])?.toString(),
);
}
}