firebase user sign up with custom fields

544 views
Skip to first unread message

Sven Arndt

unread,
May 13, 2021, 9:01:48 AM5/13/21
to Firebase Google Group
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?

Samuel Akabo

unread,
May 13, 2021, 12:51:12 PM5/13/21
to fireba...@googlegroups.com
Hi Sven,

Can you provide the code for your _userFromFirebaseUser(user) function?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/7442d0b4-bcee-4309-bc49-00d8d622db50n%40googlegroups.com.

Sven Arndt

unread,
May 14, 2021, 4:32:03 AM5/14/21
to fireba...@googlegroups.com
Morning

See below, its pretty simple at this point

// create user obj based on firebase user
User _userFromFirebaseUser(FirebaseUser user) {
return user != null ? User(id: user.uid) : null;
}

You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/UQOOO9um4Ys/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CAKK88swAAMZstB1R87x3xKsp5xB5TmDm31EHN-Sq%3D1PuMfxtEA%40mail.gmail.com.


--
Sven Arndt
Systems Analyst
c: +82 425 5034  |  t:+27 87 057 6841  | Extension: 121
e: sv...@cfo360.co.za|  w: cfo360.co.za
a: 911 Almondrock Avenue, Little Falls, Johannesburg


Review our Service
    T's & C's

The information in this email is confidential and may be legally privileged. It is intended solely for the use of the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or any action omitted as a result of reliance thereon is prohibited and may be unlawful. When addressed to our clients any opinions, advice or information contained in this email should be acted upon only after proper / adequate consultation with the engagement partner and only if supported by a signed letter from the partner. Although we make every effort to ensure this message is free of malicious program code, CFO360 accepts no liability for any loss or damage, whether direct, indirect, consequential or economic, however caused, which may result directly or indirectly from this communication or from any attached files. Save for bona fide company matters, CFO360 does not accept any responsibility for any material contained in this email.

Samuel Akabo

unread,
May 14, 2021, 5:51:41 AM5/14/21
to fireba...@googlegroups.com
Hi Sven,
All you have to do is to modify your _userFromFirebaseUser function
to accept values from the parameters you supplied in your registerWithEmailAndPassword function

Reply all
Reply to author
Forward
0 new messages