Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create user
- -------------
- Auth.auth().createUser(withEmail: "user@email.com", password: "PASSWORD******") { (user, error) in
- if let error = error {
- print(error.localizedDescription)
- }
- else if let user = user {
- print("Sign Up Successfully. \(user.uid)")
- }
- }
- ---------------------
- Login
- ---------------------
- Auth.auth().signIn(withEmail: "user@email.com", password: "PASSWORD******") { (user, error) in
- if let error = error {
- print(error.localizedDescription)
- }
- else if let user = user {
- print(user.uid)
- }
- }
- ------------------------
- SignOut
- ------------------------
- if Auth.auth().currentUser != nil {
- do {
- try Auth.auth().signOut()
- }
- catch {
- }
- }
- -------------------------
- show New VC if Succss Login or Create User
- -------------------------
- 1- add New Id to New VC Storybode `ID "Home"
- 2- add the Code
- print("Sign Up Successfully")
- let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
- self.present(viewController, animated: true, completion: nil)
- -------------------------
- 3- Code To Remember
- -----------
- import UIKit
- import Firebase
- import FirebaseAuth
- class ViewController: UIViewController {
- @IBOutlet weak var email: UITextField!
- @IBOutlet weak var password: UITextField!
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- @IBAction func Login(_ sender: Any) {
- Auth.auth().createUser(withEmail: email.text!, password: password.text!) { (user, error) in
- if let error = error {
- print(error.localizedDescription)
- }
- else if let user = user {
- print("Sign Up Successfully")
- let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home")
- self.present(viewController, animated: true, completion: nil)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment