Skip to content

Instantly share code, notes, and snippets.

@haroonkhan9426
Last active September 5, 2020 09:00
Show Gist options
  • Save haroonkhan9426/c897763ce5f2cae691e40f5595462cf7 to your computer and use it in GitHub Desktop.
Save haroonkhan9426/c897763ce5f2cae691e40f5595462cf7 to your computer and use it in GitHub Desktop.
Firebase Authentication
class FirebaseAuthHelper {
final _auth = FirebaseAuth.instance;
AuthResultStatus _status;
///
/// Helper Functions
///
Future<void> createAccount({email, pass}) async {
try {
AuthResult authResult = await _auth.createUserWithEmailAndPassword(
email: email, password: pass);
if (authResult.user != null) {
_status = AuthResultStatus.successful;
} else {
_status = AuthResultStatus.undefined;
}
} catch (e) {
print('Exception @createAccount: $e');
_status = AuthExceptionHandler.handleException(e);
}
return _status;
}
Future<AuthResultStatus> login({email, pass}) async {
try {
final authResult =
await _auth.signInWithEmailAndPassword(email: email, password: pass);
if (authResult.user != null) {
_status = AuthResultStatus.successful;
} else {
_status = AuthResultStatus.undefined;
}
} catch (e) {
print('Exception @createAccount: $e');
_status = AuthExceptionHandler.handleException(e);
}
return _status;
}
logout() {
_auth.signOut();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment