// Automatic FlutterFlow imports import '/backend/backend.dart'; import '/backend/schema/structs/index.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/actions/index.dart'; // Imports other custom actions import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom action code // DO NOT REMOVE OR MODIFY THE CODE ABOVE! import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; Future<String> addAndEditUser( String emailNewUser, String passwordCode, String messageInvalidEmail, String messageWeakPassword, String messageEmailAlreadyInUse, DocumentReference genderRef, DateTime createdProfileAt, ) async { String returnSignUp = "valid"; try { UserCredential userCredential = await FirebaseAuth.instance .createUserWithEmailAndPassword( email: emailNewUser, password: passwordCode); final myUser = userCredential.user; myUser!.updateDisplayName("Αιμοδότης"); myUser.updateEmail(emailNewUser); // set custom fields final user = FirebaseFirestore.instance.collection('users').doc(myUser.uid); user.set({ 'created_time': Timestamp.now(), 'email': emailNewUser, 'uid': myUser.uid, 'isUserActive': true, 'isComplete': false, 'isAdmin': false, 'isNyaUser': false, 'eventCanceled': false, 'eventChanged': false, 'Newsletters': false, 'gender': genderRef, 'justCompletedAppointment': false, 'createdProfileAt': createdProfileAt }); } on FirebaseAuthException catch (e) { switch (e.code) { case 'invalid-email': returnSignUp = messageInvalidEmail; break; case 'weak-password': returnSignUp = messageWeakPassword; break; case 'email-already-in-use': returnSignUp = messageEmailAlreadyInUse; break; } } return returnSignUp; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter