Created
March 2, 2022 21:06
-
-
Save haIIux/043865a031f0346275b854f580057bd5 to your computer and use it in GitHub Desktop.
Firebase authentication intial view setup.
This file contains hidden or 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
// 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