Last active
September 5, 2020 09:00
-
-
Save haroonkhan9426/c897763ce5f2cae691e40f5595462cf7 to your computer and use it in GitHub Desktop.
Firebase Authentication
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
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