update
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:prosappco/src/authentication/exceptions/register_failed.dart';
|
||||
@@ -11,7 +13,9 @@ class AuthenticationRepository extends GetxController {
|
||||
//Variables
|
||||
final _auth = FirebaseAuth.instance;
|
||||
late final Rx<User?> firebaseUser;
|
||||
final firebase = FirebaseFirestore.instance;
|
||||
final GoogleSignIn googleSignIn = GoogleSignIn();
|
||||
// final _userRef = firebase
|
||||
var verificationId = ''.obs;
|
||||
|
||||
@override
|
||||
@@ -60,8 +64,17 @@ class AuthenticationRepository extends GetxController {
|
||||
Future<void> createUserWithEmailAndPassword(
|
||||
String email, String password) async {
|
||||
try {
|
||||
// try {
|
||||
// await firebase.collection('Users').doc().set({
|
||||
// "Email": email,
|
||||
// "Password": password,
|
||||
// });
|
||||
// } catch (e) {
|
||||
// print('Error $e');
|
||||
// }
|
||||
await _auth.createUserWithEmailAndPassword(
|
||||
email: email, password: password);
|
||||
|
||||
firebaseUser.value != null
|
||||
? Get.offAll(() => WelcomeScreen())
|
||||
: Get.to(() => LoginScreen());
|
||||
@@ -98,4 +111,50 @@ class AuthenticationRepository extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> logout() async => _auth.signOut();
|
||||
|
||||
String? getCurrentUserPhone() {
|
||||
final User? user = _auth.currentUser;
|
||||
return user?.phoneNumber;
|
||||
}
|
||||
|
||||
String? getCurrentUserUid() {
|
||||
final User? user = _auth.currentUser;
|
||||
return user?.uid;
|
||||
}
|
||||
|
||||
Future<void> addNameAndEmail(
|
||||
uid, String name, String email, String city) async {
|
||||
final usersCollection = FirebaseFirestore.instance.collection('users');
|
||||
await usersCollection.doc(uid).set({
|
||||
'name': name,
|
||||
'email': email,
|
||||
'city': city,
|
||||
});
|
||||
}
|
||||
|
||||
Future<String> getName(String uid) async {
|
||||
String city = 'error';
|
||||
CollectionReference collectionUsers =
|
||||
FirebaseFirestore.instance.collection('users');
|
||||
DocumentSnapshot snapshot = await collectionUsers.doc(uid).get();
|
||||
|
||||
final Map<String, dynamic> doc = snapshot.data() as Map<String, dynamic>;
|
||||
if (doc['name'] != null) {
|
||||
city = doc['name'];
|
||||
}
|
||||
return city;
|
||||
}
|
||||
|
||||
Future<String> getCity(String uid) async {
|
||||
String city = 'error';
|
||||
CollectionReference collectionUsers =
|
||||
FirebaseFirestore.instance.collection('users');
|
||||
DocumentSnapshot snapshot = await collectionUsers.doc(uid).get();
|
||||
|
||||
final Map<String, dynamic> doc = snapshot.data() as Map<String, dynamic>;
|
||||
if (doc['city'] != null) {
|
||||
city = doc['city'];
|
||||
}
|
||||
return city;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user