Skip to content

Instantly share code, notes, and snippets.

@haIIux
Created March 2, 2022 21:06
Show Gist options
  • Save haIIux/043865a031f0346275b854f580057bd5 to your computer and use it in GitHub Desktop.
Save haIIux/043865a031f0346275b854f580057bd5 to your computer and use it in GitHub Desktop.
Firebase authentication intial view setup.
// Main App File.
import SwiftUI
import Firebase
@main
struct MediumArticleApp: App {
@StateObject var authViewModel = AuthViewModel()
init() {
FirebaseApp.app()
}
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(authViewModel)
}
}
}
// Content View file.
import SwiftUI
struct ContentView: View {
@State private var email = ""
@State private var password = ""
@State private var fullname = ""
@State private var username = ""
@EnvironmentObject var authViewModel: AuthViewModel
var body: some View {
VStack {
TextField("Full Name", text: $fullname)
TextField("Username", text: $username)
TextField("Email", text: $email)
SecureField("Password", text: $password)
Button {
authViewModel.registerUser(withEmail: email, password: password, fullname: fullname, username: username)
} label: {
Text("Submit Registration")
}
.padding(.top)
}
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.horizontal)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment