Skip to content

Commit 21028a8

Browse files
committed
✨ Sign up with email / password
Signed-off-by: Peter Friese <[email protected]>
1 parent 5b5f467 commit 21028a8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Examples/FriendlyFlix/app/FriendlyFlix/FriendlyFlix/Features/Authentication/AuthenticationScreen.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff 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)

Examples/FriendlyFlix/app/FriendlyFlix/FriendlyFlix/Features/Authentication/AuthenticationService.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)