bLOQUE p1 BACKEND Y SEGURIDAD, AUTENTICACION CON SUPABASE. jwt. RBAC CRUD
This commit is contained in:
0
recolecta_app/lib/core/models/.gitkeep
Normal file
0
recolecta_app/lib/core/models/.gitkeep
Normal file
22
recolecta_app/lib/core/models/address.dart
Normal file
22
recolecta_app/lib/core/models/address.dart
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
11
recolecta_app/lib/core/models/auth_session.dart
Normal file
11
recolecta_app/lib/core/models/auth_session.dart
Normal 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';
|
||||
}
|
||||
28
recolecta_app/lib/core/models/auth_state.dart
Normal file
28
recolecta_app/lib/core/models/auth_state.dart
Normal 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;
|
||||
}
|
||||
37
recolecta_app/lib/core/models/colonia.dart
Normal file
37
recolecta_app/lib/core/models/colonia.dart
Normal 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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user