Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
Last active October 9, 2020 23:50
Show Gist options
  • Save SlappyAUS/ed411156417b58db8e3f537e284a4bff to your computer and use it in GitHub Desktop.
Save SlappyAUS/ed411156417b58db8e3f537e284a4bff to your computer and use it in GitHub Desktop.
User Management #firebase
// 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