How do I use Firebase Authentication using multiple view controllers?
How do I use Firebase Authentication using multiple view controllers?
I am in the process of adding the Create new user Method for Firebase. I have already completed the SignUp Auth process. However when users are creating a new account. How do I go about this if I have multiple ViewControllers?
Firebase
SignUp
ViewControllers
For example,
The First SignUpViewController - User is asked to enter their email address.
SignUpViewController
When the user clicks next. This is then followed by another ViewController.
ViewController
SecondViewControlle - User is asked to enter their name and create a password.
SecondViewControlle
After this, The user is greeted with a Welcome page with their name they submitted. (Welcome to “App Name” Name). Which will then proceed to the home UI after next is clicked.
How do I implement The Auth.auth().CreateUserwith func when I have more than one ViewController? Is there a way to save the email and password using two different ViewControllers?
Auth.auth().CreateUserwith
func
ViewController
ViewControllers
Update**
I have added the following code that was suggested below, however the App crashes every time I click next on the enter your " Email" View Controller. I am getting this warning. Does anyone know what I did wrong? The rest of the code seems to be working fine. Here is a screenshot. 
Singleton Class
Singleton Class
Dictionary
Thank you for your quick response. I will try this!
– Clint
Sep 3 at 6:19
Hey! Have you tried below solution?
– TheTiger
Sep 3 at 6:41
I have not yet but I will definitely let you know!
– Clint
Sep 3 at 7:02
Actually I got down vote so I thought it was you. I just wanted to know what is wrong in the answer. But anyway .. 👍
– TheTiger
Sep 3 at 7:04
1 Answer
1
You can save all information in a Dictionary and use it at the time of SignUp. In your AppDelegate class:
Dictionary
SignUp
AppDelegate
/// Instance of AppDelegate
static let shared: AppDelegate = UIApplication.shared.delegate as! AppDelegate
/// Dictionary for user information
var userInformation: Dictionary<String, Any> = [:]
On Email Screen - Next Button Click
/// #1. Validate the email address
/// #2. Save it in Dictionary
AppDelegate.shared.userInformation["email"] = "xyz@gmail.com" or tFEmail.text.lowercased()
Then On name and password screen
AppDelegate.shared.userInformation["name"] = "xyz" or tFName.text
AppDelegate.shared.userInformation["password"] = "xxxxxxx" or tFPassword.text
Now on last screen - Sign Up Button clicked you can use all this information
let email = AppDelegate.shared.userInformation["email"]
let name = AppDelegate.shared.userInformation["name"]
let password = AppDelegate.shared.userInformation["password"]
Implement the Firebase SignUp method and after successfully logged in show the welcome screen.
Sorry for the late response mate. I have updated my question with a new warning I am getting after trying out your code. Everything seems to be in working order but the App Delegate. I have added a screenshot above. Did I miss something?
– Clint
Sep 6 at 21:55
Hey it should be 'UIApplication.shared.delegate' sorry it's typo mistake from my end. I have updated my answer as well.
– TheTiger
Sep 7 at 3:20
Great! That solved that issue thanks mate. I do have one more issue now and I think this will fix it for good. Do I update my question or ask a completely new one? Sorry I am still new to stackoverflow.
– Clint
Sep 7 at 4:05
You should ask a different question instead.
– TheTiger
Sep 7 at 4:29
Will do thank you for your assistance!
– Clint
Sep 7 at 4:41
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Make a
Singleton Classand save user's account information in it and process one by one then implement Firebase signup method in last controller with information you have inSingleton Class. After successfully logged in show him the Welcome screen. Or you can useDictionaryas well.– TheTiger
Sep 3 at 6:07