File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
Examples/FriendlyFlix/app/FriendlyFlix/FriendlyFlix/Features/Authentication Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -73,13 +73,16 @@ struct AuthenticationScreen: View {
7373 }
7474
7575 private func signUpWithEmailPassword( ) {
76- if authenticationService. authenticationState == . authenticated {
77- authenticationService. authenticationState = . unauthenticated
78- dismiss ( )
79- }
80- else {
81- authenticationService. authenticationState = . authenticated
82- dismiss ( )
76+ Task {
77+ do {
78+ try await authenticationService. signUpWithEmailPassword ( email: email, password: password)
79+ errorMessage = " "
80+ dismiss ( )
81+ }
82+ catch {
83+ print ( error. localizedDescription)
84+ errorMessage = error. localizedDescription
85+ }
8386 }
8487 }
8588}
@@ -147,7 +150,10 @@ extension AuthenticationScreen {
147150 }
148151 }
149152
150- Button ( action: signInWithEmailPassword) {
153+ Button ( action: {
154+ if flow == . login { signInWithEmailPassword ( ) }
155+ else { signUpWithEmailPassword ( ) }
156+ } ) {
151157 if authenticationService. authenticationState != . authenticating {
152158 Text ( flow == . login ? " Log in with password " : " Sign up " )
153159 . padding ( . vertical, 8 )
Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ class AuthenticationService {
4949 authenticationState = . authenticated
5050 }
5151
52+ func signUpWithEmailPassword( email: String , password: String ) async throws {
53+ try await Auth . auth ( ) . createUser ( withEmail: email, password: password)
54+ authenticationState = . authenticated
55+ }
56+
5257 func signOut( ) throws {
5358 try Auth . auth ( ) . signOut ( )
5459 authenticationState = . unauthenticated
You can’t perform that action at this time.
0 commit comments