-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
185 changed files
with
1,225 additions
and
757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter_bootstrap/data/repositories/auth.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
import 'bloc/auth_bloc.dart'; | ||
import 'pages/login.dart'; | ||
import 'pages/home.dart'; | ||
import 'pages/profile.dart'; | ||
|
||
part 'app_router.gr.dart'; | ||
|
||
@Injectable() | ||
class AuthGuard extends AutoRedirectGuard { | ||
final AuthBloc authBloc; | ||
final AuthRepository authRepository; | ||
late final StreamSubscription<AuthState> _stream; | ||
|
||
AuthGuard(this.authBloc, this.authRepository) { | ||
_stream = authBloc.stream.listen((state) { | ||
state.maybeMap( | ||
orElse: () { | ||
reevaluate(); | ||
}, | ||
loaded: (_) {}, | ||
); | ||
}); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_stream.cancel(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void onNavigation(NavigationResolver resolver, StackRouter router) { | ||
authBloc.state.maybeMap( | ||
orElse: () { | ||
if (authRepository.getUser() == null) { | ||
router.push( | ||
LoginRoute(authBloc: authBloc, authRepository: authRepository)); | ||
} else { | ||
resolver.next(true); | ||
} | ||
}, | ||
loading: (_) => {}, | ||
loaded: (_) => resolver.next(true)); | ||
} | ||
|
||
@override | ||
Future<bool> canNavigate(RouteMatch route) { | ||
return Future.value(authBloc.state is Loaded); | ||
} | ||
} | ||
|
||
@MaterialAutoRouter( | ||
replaceInRouteName: 'Page,Route', | ||
routes: <AutoRoute>[ | ||
AutoRoute( | ||
initial: true, | ||
guards: [AuthGuard], | ||
page: HomePage, | ||
children: [ | ||
AutoRoute(page: ProfilePage), | ||
], | ||
), | ||
AutoRoute( | ||
page: LoginPage, | ||
), | ||
], | ||
) | ||
@Injectable() | ||
class AppRouter extends _$AppRouter { | ||
AppRouter({required super.authGuard}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
import '../data/repositories/auth.dart'; | ||
|
||
part 'auth_event.dart'; | ||
part 'auth_state.dart'; | ||
part 'auth_bloc.freezed.dart'; | ||
|
||
@singleton | ||
class AuthBloc extends Bloc<AuthEvent, AuthState> { | ||
final AuthRepository authRepository; | ||
|
||
AuthBloc(this.authRepository) : super(const Initial()) { | ||
on<_Started>((event, emit) { | ||
// nothing here for now | ||
}); | ||
|
||
on<_SignIn>((event, emit) async { | ||
emit(const Loading()); | ||
|
||
await authRepository.signInWithEmailAndPassword( | ||
email: event.email, password: event.password); | ||
|
||
if (authRepository.getUser() != null) { | ||
emit(const Loaded()); | ||
} else { | ||
emit(const Errored()); | ||
} | ||
}); | ||
|
||
on<_Logout>((event, emit) async { | ||
await authRepository.signOut(); | ||
|
||
emit(const Initial()); | ||
}); | ||
|
||
@disposeMethod | ||
// ignore: unused_element | ||
void dispose() { | ||
close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
part of 'auth_bloc.dart'; | ||
|
||
@freezed | ||
class AuthEvent with _$AuthEvent { | ||
const factory AuthEvent.started() = _Started; | ||
|
||
const factory AuthEvent.signIn({ | ||
email, | ||
password | ||
}) = _SignIn; | ||
|
||
const factory AuthEvent.logout() = _Logout; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
part of 'auth_bloc.dart'; | ||
|
||
@freezed | ||
class AuthState with _$AuthState { | ||
const factory AuthState.initial() = Initial; | ||
|
||
const factory AuthState.loading() = Loading; | ||
|
||
const factory AuthState.loaded() = Loaded; | ||
|
||
const factory AuthState.error() = Errored; | ||
} |
18 changes: 8 additions & 10 deletions
18
lib/components/app_drawer.dart → apps/main/lib/components/app_drawer.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:authentication/authentication.dart'; | ||
import 'package:firebase_authentication/firebase_authentication.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
|
||
import '../models/user.dart'; | ||
|
||
@Injectable() | ||
class AuthRepository extends FirebaseAuthentication implements Authentication { | ||
User? getUser() { | ||
final user = super.currentUser; | ||
|
||
return user == null | ||
? null | ||
: User(id: user.uid, email: user.email, username: user.displayName); | ||
} | ||
|
||
@override | ||
Future<void> signInWithEmailAndPassword( | ||
{required String email, required String password}) async { | ||
|
||
return await super.signInWithEmailAndPassword(email: email, password: password); | ||
} | ||
|
||
@override | ||
Future<void> createUserWithEmailAndPassword( | ||
{required String email, required String password}) async { | ||
|
||
return await super.createUserWithEmailAndPassword(email: email, password: password); | ||
} | ||
|
||
@override | ||
Future<void> signOut() async { | ||
return await super.signOut(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.