Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>
Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com> Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> modificacion de vistas panel admin, login, animaciones y implementacion de mascota
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:recolecta_app/features/admin/admin_shell.dart';
|
||||
import 'package:recolecta_app/features/auth/login_page.dart';
|
||||
import 'package:recolecta_app/features/splash/splash_screen.dart';
|
||||
import 'package:recolecta_app/features/auth/register_page.dart';
|
||||
import 'package:recolecta_app/features/driver/driver_shell.dart';
|
||||
import 'package:recolecta_app/features/driver/screens/driver_collections_screen.dart';
|
||||
@@ -43,20 +44,21 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
final authState = ref.watch(authControllerProvider);
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/login',
|
||||
initialLocation: '/splash',
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
final isAuthenticated = authState.value?.isAuthenticated ?? false;
|
||||
final role = authState.value?.userRole;
|
||||
|
||||
final isAuthRoute =
|
||||
final isPublicRoute =
|
||||
state.matchedLocation == '/splash' ||
|
||||
state.matchedLocation == '/login' ||
|
||||
state.matchedLocation == '/register';
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return isAuthRoute ? null : '/login';
|
||||
return isPublicRoute ? null : '/login';
|
||||
}
|
||||
|
||||
if (isAuthRoute) {
|
||||
if (isPublicRoute) {
|
||||
switch (role) {
|
||||
case 'admin':
|
||||
return '/admin';
|
||||
@@ -72,6 +74,10 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/splash',
|
||||
builder: (context, state) => const SplashScreen(),
|
||||
),
|
||||
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
|
||||
GoRoute(
|
||||
path: '/register',
|
||||
|
||||
@@ -44,6 +44,7 @@ class AuthController extends AsyncNotifier<AuthState> {
|
||||
}
|
||||
|
||||
Future<void> register({
|
||||
required String name,
|
||||
required String email,
|
||||
required String phone,
|
||||
required String password,
|
||||
@@ -55,16 +56,19 @@ class AuthController extends AsyncNotifier<AuthState> {
|
||||
}) async {
|
||||
state = const AsyncLoading<AuthState>();
|
||||
try {
|
||||
final session = await ref.read(authServiceProvider).register(
|
||||
email: email,
|
||||
phone: phone,
|
||||
password: password,
|
||||
addressCalle: addressCalle,
|
||||
addressColonia: addressColonia,
|
||||
addressLabel: addressLabel,
|
||||
addressLat: addressLat,
|
||||
addressLng: addressLng,
|
||||
);
|
||||
final session = await ref
|
||||
.read(authServiceProvider)
|
||||
.register(
|
||||
name: name,
|
||||
email: email,
|
||||
phone: phone,
|
||||
password: password,
|
||||
addressCalle: addressCalle,
|
||||
addressColonia: addressColonia,
|
||||
addressLabel: addressLabel,
|
||||
addressLat: addressLat,
|
||||
addressLng: addressLng,
|
||||
);
|
||||
|
||||
final authState = AuthState.authenticated(
|
||||
token: session.token,
|
||||
|
||||
@@ -38,6 +38,7 @@ class AuthService {
|
||||
}
|
||||
|
||||
Future<AuthSession> register({
|
||||
required String name,
|
||||
required String email,
|
||||
required String phone,
|
||||
required String password,
|
||||
@@ -50,6 +51,7 @@ class AuthService {
|
||||
return _authenticate(
|
||||
path: '/auth/register',
|
||||
payload: <String, dynamic>{
|
||||
'name': name,
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
'password': password,
|
||||
|
||||
Reference in New Issue
Block a user