-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.dart
39 lines (32 loc) · 1.12 KB
/
auth.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'package:firebase_auth/firebase_auth.dart';
import 'package:furnitureshop/user.dart';
class AuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
User _userFromFirebaseUser(FirebaseUser user){
return user!=null ?User (uid:user.uid) :" no user" ;
}
// sign in with email and password
Future signInEmailAndPass(String email, String password) async{
try{
AuthResult authResult = await _auth.signInWithEmailAndPassword(email: email.trim(), password: password);
FirebaseUser firebaseUser = authResult.user;
return _userFromFirebaseUser(firebaseUser);
}catch(e){
print(e);
}
}
// register with email and password
Future registerWithEmailAndPassword(String email, String password) async {
try {
// registering user..
AuthResult authResult = await _auth.createUserWithEmailAndPassword(
email: email.trim(),
password: password);
FirebaseUser firebaseUser = authResult.user;
return _userFromFirebaseUser(firebaseUser);
} catch (e) {
print(e.toString());
return null;
}
}
}