Hi All
I need assistance with making the link between firebase and a user signup with custom fields that it goes to a collection of users which has been made already. Code for the users page is:
class User {
final String id;
final String fullName;
final String userType;
final String email;
final String cellphone;
final String dateOfBirth;
final String companyName;
User({
this.id, this.fullName, this.userType, this.email, this.cellphone, this.dateOfBirth, this.companyName });
User.fromData(Map<String, dynamic> data)
: id =data['id'], fullName = data['fullName'],userType = data['userType'],email = data['email'],
cellphone = data['cellphone'],companyName = data['companyName'],dateOfBirth = data['dateOfBirth'];
Map<String, dynamic> toJson() {
return {
'id' : id,
'fullName' : fullName,
'userType' : userType,
'email' : email,
'cellphone' : cellphone,
'dateOfBirth' : dateOfBirth,
'companyName' : companyName,
};
}
}
And then the code for the auth that relates to this is:
Future registerWithEmailAndPassword(String email, String password, String fullName, String userType, String dateOfBirth, String cellphone, String companyName) async {
try {
AuthResult result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user = result.user;
return _userFromFirebaseUser(user);
} catch(e) {
print(e.toString());
return null;
}
}
Which needs to change to include the fields I believe, but not sure about this portion of it.
And then last is the firestore service:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cfo360app/models/users.dart';
class firestoreService {
final CollectionReference _usersCollectionReference =
Firestore.
instance.collection('users');
Future createUser(User user) async {
try {
await _usersCollectionReference.document(
user.id).setData(user.toJson());
}catch (e) {
return e.message;
}
}
}
But I am unsure of what part I am missing to complete this, can anyone advise?