Skip to content

Commit

Permalink
Merge pull request #146 from PDG-NUTRI/145-fix-guards
Browse files Browse the repository at this point in the history
145 fix guards
  • Loading branch information
chloefont authored Sep 3, 2022
2 parents 4fd0376 + 55e67c9 commit 7c512b2
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Future<void> setup() async {
clientApi: FirebaseUser(FirebaseFirestore.instance),
),
);
await GetIt.I.get<AuthProvider>().init();
}

void main() async {
Expand Down
19 changes: 15 additions & 4 deletions lib/provider/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class AuthProvider extends ChangeNotifier {
: _auth = auth,
_userApi = clientApi;

Future<void> init() async {
if (isConnected()) {
final values = await Future.wait([
fetchClient(),
_auth.isDietitian(),
]);

_isAdmin = values[1] as bool;
}
}

bool get isAdmin => _isAdmin;

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

Future<void> signIn(String email, String password) async {
//final isConnected = await _auth.signIn(email: email, password: password);
final isConnected =
await _auth.signIn(email: "[email protected]", password: 'crepes');
final isConnected = await _auth.signIn(email: email, password: password);
//final isConnected =
//await _auth.signIn(email: "[email protected]", password: 'crepes');
_isAdmin = await _auth.isDietitian();
if (isConnected) {
fetchClient();
await fetchClient();
}

notifyListeners();
Expand Down
5 changes: 1 addition & 4 deletions lib/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import 'home_guard.dart';
guards: [AuthGuard],
initial: true,
children: [
RedirectRoute(
path: '',
redirectTo: 'diary',
),
AutoRoute(
page: EmptyRouterPage,
name: 'ChatRouterPage',
Expand All @@ -57,6 +53,7 @@ import 'home_guard.dart';
AutoRoute(
page: EmptyRouterPage,
name: "MainRouterPage",
initial: true,
path: 'main',
children: [
AutoRoute(
Expand Down
2 changes: 1 addition & 1 deletion lib/router/router.gr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AppRouter extends _i16.RootStackRouter {
_i16.RouteConfig('#redirect',
path: '',
parent: HomeScreenRoute.name,
redirectTo: 'diary',
redirectTo: 'main',
fullMatch: true),
_i16.RouteConfig(ChatRouterPage.name,
path: 'chat',
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _LoginScreenState extends State<LoginScreen> {
await auth.signIn(_emailController.text, _passwordController.text);
if (auth.isConnected()) {
// ignore: use_build_context_synchronously
AutoRouter.of(context).navigate(const HomeScreenRoute());
AutoRouter.of(context).replaceAll([const HomeScreenRoute()]);
} else {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
Expand Down
4 changes: 3 additions & 1 deletion lib/screens/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class ProfileScreen extends StatelessWidget {
clientInsurance: "09734789789248943",
onLogoutPressed: () {
GetIt.I.get<AuthProvider>().signOut();
AutoRouter.of(context).navigate(const LoginScreenRoute());
context.router.replaceAll([
const LoginScreenRoute(),
]);
},
);
}
Expand Down
11 changes: 2 additions & 9 deletions lib/screens/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,24 @@ import 'package:pdg_app/widgets/register/top_shape.dart';
import 'package:pdg_app/widgets/register/bottom_shape.dart';
import 'package:provider/provider.dart';

import '../router/router.gr.dart';

class RegisterScreen extends StatelessWidget {
const RegisterScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: Register(
onRegisterPress: () =>
AutoRouter.of(context).navigate(const RegisterScreenRoute()),
),
return const Scaffold(
body: Register(),
);

/// Navigating to the RegisterScreenRoute.
}
}

class Register extends StatelessWidget {
final void Function()? onRegisterPress;
final double screenWidth;

const Register({
this.screenWidth = 0,
this.onRegisterPress,
Key? key,
}) : super(key: key);

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/register/register_third_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _RegisterThirdPageState extends State<RegisterThirdPage> {
registerProvider.createUser(),
);

router.push(const HomeScreenRoute());
router.replaceAll([const HomeScreenRoute()]);
}),
),
],
Expand Down
31 changes: 19 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.9.0"
version: "2.8.2"
auto_route:
dependency: "direct main"
description:
Expand Down Expand Up @@ -112,7 +112,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
checked_yaml:
dependency: transitive
description:
Expand All @@ -126,7 +133,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
version: "1.1.0"
cloud_firestore:
dependency: "direct main"
description:
Expand Down Expand Up @@ -245,7 +252,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.3.0"
fake_cloud_firestore:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -596,21 +603,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.12"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
version: "0.1.4"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.7.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -638,7 +645,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.8.1"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -804,7 +811,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -832,7 +839,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
version: "1.1.0"
table_calendar:
dependency: "direct main"
description:
Expand All @@ -846,14 +853,14 @@ packages:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.12"
version: "0.4.9"
timing:
dependency: transitive
description:
Expand Down

0 comments on commit 7c512b2

Please sign in to comment.