Last active
October 9, 2020 23:50
-
-
Save SlappyAUS/ed411156417b58db8e3f537e284a4bff to your computer and use it in GitHub Desktop.
User Management #firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App Delegate | |
import Firebase | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool | |
{ | |
FirebaseApp.configure() | |
return true | |
} | |
// Register User Controller | |
import Firebase | |
// Register User | |
@IBAction func registerPressed(_ sender: UIButton) { | |
errorLabel.text = "" | |
if let email = emailTextfield.text, let password = passwordTextfield.text { | |
Auth.auth().createUser(withEmail: email, password: password) { authResult, error in | |
if let err = error { | |
self.errorLabel.text = err.localizedDescription | |
} else { | |
// Navigate to the chat view controller | |
self.performSegue(withIdentifier: "RegisterToChat", sender: self) | |
} | |
} | |
} | |
} | |
// Login User Controller | |
import Firebase | |
// Login User | |
@IBAction func loginPressed(_ sender: UIButton) { | |
if let email = emailTextfield.text, let password = passwordTextfield.text { | |
Auth.auth().signIn(withEmail: email, password: password) { authResult, error in | |
if let err = error { | |
print(err) | |
} else { | |
self.performSegue(withIdentifier: "LoginToChat", sender: self) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment