Skip to content

Commit 7c512b2

Browse files
authored
Merge pull request #146 from PDG-NUTRI/145-fix-guards
145 fix guards
2 parents 4fd0376 + 55e67c9 commit 7c512b2

File tree

9 files changed

+44
-33
lines changed

9 files changed

+44
-33
lines changed

lib/main.dart

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Future<void> setup() async {
2222
clientApi: FirebaseUser(FirebaseFirestore.instance),
2323
),
2424
);
25+
await GetIt.I.get<AuthProvider>().init();
2526
}
2627

2728
void main() async {

lib/provider/auth_provider.dart

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ class AuthProvider extends ChangeNotifier {
1717
: _auth = auth,
1818
_userApi = clientApi;
1919

20+
Future<void> init() async {
21+
if (isConnected()) {
22+
final values = await Future.wait([
23+
fetchClient(),
24+
_auth.isDietitian(),
25+
]);
26+
27+
_isAdmin = values[1] as bool;
28+
}
29+
}
30+
2031
bool get isAdmin => _isAdmin;
2132

2233
User? get user => _client;
@@ -28,12 +39,12 @@ class AuthProvider extends ChangeNotifier {
2839
}
2940

3041
Future<void> signIn(String email, String password) async {
31-
//final isConnected = await _auth.signIn(email: email, password: password);
32-
final isConnected =
33-
await _auth.signIn(email: "[email protected]", password: 'crepes');
42+
final isConnected = await _auth.signIn(email: email, password: password);
43+
//final isConnected =
44+
//await _auth.signIn(email: "[email protected]", password: 'crepes');
3445
_isAdmin = await _auth.isDietitian();
3546
if (isConnected) {
36-
fetchClient();
47+
await fetchClient();
3748
}
3849

3950
notifyListeners();

lib/router/router.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ import 'home_guard.dart';
2929
guards: [AuthGuard],
3030
initial: true,
3131
children: [
32-
RedirectRoute(
33-
path: '',
34-
redirectTo: 'diary',
35-
),
3632
AutoRoute(
3733
page: EmptyRouterPage,
3834
name: 'ChatRouterPage',
@@ -57,6 +53,7 @@ import 'home_guard.dart';
5753
AutoRoute(
5854
page: EmptyRouterPage,
5955
name: "MainRouterPage",
56+
initial: true,
6057
path: 'main',
6158
children: [
6259
AutoRoute(

lib/router/router.gr.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class AppRouter extends _i16.RootStackRouter {
141141
_i16.RouteConfig('#redirect',
142142
path: '',
143143
parent: HomeScreenRoute.name,
144-
redirectTo: 'diary',
144+
redirectTo: 'main',
145145
fullMatch: true),
146146
_i16.RouteConfig(ChatRouterPage.name,
147147
path: 'chat',

lib/screens/login.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class _LoginScreenState extends State<LoginScreen> {
3838
await auth.signIn(_emailController.text, _passwordController.text);
3939
if (auth.isConnected()) {
4040
// ignore: use_build_context_synchronously
41-
AutoRouter.of(context).navigate(const HomeScreenRoute());
41+
AutoRouter.of(context).replaceAll([const HomeScreenRoute()]);
4242
} else {
4343
// ignore: use_build_context_synchronously
4444
ScaffoldMessenger.of(context).showSnackBar(

lib/screens/profile.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class ProfileScreen extends StatelessWidget {
2424
clientInsurance: "09734789789248943",
2525
onLogoutPressed: () {
2626
GetIt.I.get<AuthProvider>().signOut();
27-
AutoRouter.of(context).navigate(const LoginScreenRoute());
27+
context.router.replaceAll([
28+
const LoginScreenRoute(),
29+
]);
2830
},
2931
);
3032
}

lib/screens/register.dart

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,24 @@ import 'package:pdg_app/widgets/register/top_shape.dart';
55
import 'package:pdg_app/widgets/register/bottom_shape.dart';
66
import 'package:provider/provider.dart';
77

8-
import '../router/router.gr.dart';
9-
108
class RegisterScreen extends StatelessWidget {
119
const RegisterScreen({Key? key}) : super(key: key);
1210

1311
@override
1412
Widget build(BuildContext context) {
15-
return Scaffold(
16-
body: Register(
17-
onRegisterPress: () =>
18-
AutoRouter.of(context).navigate(const RegisterScreenRoute()),
19-
),
13+
return const Scaffold(
14+
body: Register(),
2015
);
2116

2217
/// Navigating to the RegisterScreenRoute.
2318
}
2419
}
2520

2621
class Register extends StatelessWidget {
27-
final void Function()? onRegisterPress;
2822
final double screenWidth;
2923

3024
const Register({
3125
this.screenWidth = 0,
32-
this.onRegisterPress,
3326
Key? key,
3427
}) : super(key: key);
3528

lib/widgets/register/register_third_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class _RegisterThirdPageState extends State<RegisterThirdPage> {
4747
registerProvider.createUser(),
4848
);
4949

50-
router.push(const HomeScreenRoute());
50+
router.replaceAll([const HomeScreenRoute()]);
5151
}),
5252
),
5353
],

pubspec.lock

+19-12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ packages:
2828
name: async
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "2.9.0"
31+
version: "2.8.2"
3232
auto_route:
3333
dependency: "direct main"
3434
description:
@@ -112,7 +112,14 @@ packages:
112112
name: characters
113113
url: "https://pub.dartlang.org"
114114
source: hosted
115-
version: "1.2.1"
115+
version: "1.2.0"
116+
charcode:
117+
dependency: transitive
118+
description:
119+
name: charcode
120+
url: "https://pub.dartlang.org"
121+
source: hosted
122+
version: "1.3.1"
116123
checked_yaml:
117124
dependency: transitive
118125
description:
@@ -126,7 +133,7 @@ packages:
126133
name: clock
127134
url: "https://pub.dartlang.org"
128135
source: hosted
129-
version: "1.1.1"
136+
version: "1.1.0"
130137
cloud_firestore:
131138
dependency: "direct main"
132139
description:
@@ -245,7 +252,7 @@ packages:
245252
name: fake_async
246253
url: "https://pub.dartlang.org"
247254
source: hosted
248-
version: "1.3.1"
255+
version: "1.3.0"
249256
fake_cloud_firestore:
250257
dependency: "direct dev"
251258
description:
@@ -596,21 +603,21 @@ packages:
596603
name: matcher
597604
url: "https://pub.dartlang.org"
598605
source: hosted
599-
version: "0.12.12"
606+
version: "0.12.11"
600607
material_color_utilities:
601608
dependency: transitive
602609
description:
603610
name: material_color_utilities
604611
url: "https://pub.dartlang.org"
605612
source: hosted
606-
version: "0.1.5"
613+
version: "0.1.4"
607614
meta:
608615
dependency: transitive
609616
description:
610617
name: meta
611618
url: "https://pub.dartlang.org"
612619
source: hosted
613-
version: "1.8.0"
620+
version: "1.7.0"
614621
mime:
615622
dependency: transitive
616623
description:
@@ -638,7 +645,7 @@ packages:
638645
name: path
639646
url: "https://pub.dartlang.org"
640647
source: hosted
641-
version: "1.8.2"
648+
version: "1.8.1"
642649
path_provider:
643650
dependency: "direct main"
644651
description:
@@ -804,7 +811,7 @@ packages:
804811
name: source_span
805812
url: "https://pub.dartlang.org"
806813
source: hosted
807-
version: "1.9.0"
814+
version: "1.8.2"
808815
stack_trace:
809816
dependency: transitive
810817
description:
@@ -832,7 +839,7 @@ packages:
832839
name: string_scanner
833840
url: "https://pub.dartlang.org"
834841
source: hosted
835-
version: "1.1.1"
842+
version: "1.1.0"
836843
table_calendar:
837844
dependency: "direct main"
838845
description:
@@ -846,14 +853,14 @@ packages:
846853
name: term_glyph
847854
url: "https://pub.dartlang.org"
848855
source: hosted
849-
version: "1.2.1"
856+
version: "1.2.0"
850857
test_api:
851858
dependency: transitive
852859
description:
853860
name: test_api
854861
url: "https://pub.dartlang.org"
855862
source: hosted
856-
version: "0.4.12"
863+
version: "0.4.9"
857864
timing:
858865
dependency: transitive
859866
description:

0 commit comments

Comments
 (0)