Skip to content

Instantly share code, notes, and snippets.

@trongdth
Last active January 14, 2021 07:17
Show Gist options
  • Save trongdth/b6ae8ce2357eb6cf4e283e00cbf6aace to your computer and use it in GitHub Desktop.
Save trongdth/b6ae8ce2357eb6cf4e283e00cbf6aace to your computer and use it in GitHub Desktop.
import 'package:bloc/bloc.dart';
import 'package:flutter_bloc_back4app/blocs/auth/auth_states.dart';
import 'package:flutter_bloc_back4app/repositories/user_repos.dart';
import 'package:meta/meta.dart';
class AuthCubit extends Cubit<AuthenticationState> {
final BaseUserRepository userRepository;
AuthCubit({@required this.userRepository})
: assert(userRepository != null),
super(AuthenticationUninitialized());
Future<void> appStarted() async {
var user = await userRepository.currentUser();
if (user != null) {
emit(AuthenticationAuthenticated());
} else {
emit(AuthenticationUnauthenticated());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment