diff --git a/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailAuthView.swift b/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailAuthView.swift index 8d9d01068..bf770c5af 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailAuthView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailAuthView.swift @@ -14,22 +14,11 @@ enum EmailAuthState { @MainActor final class EmailAuthViewModel: ObservableObject { @Published var loginError: LoginError? - @Published var emailAuthState = EmailAuthState.loading + @Published var emailAuthState = EmailAuthState.signIn @Published var potentialUsernameStatus = PotentialUsernameStatus.noUsername @Published var potentialUsername = "" var subscriptions = Set() - - func loadAuthState() { - // check tokens here to determine pending/active/no user - if PublicValet.hasPendingEmailVerificationToken { - // TODO: make network request to check status - // if it's now active then log in the user\ - emailAuthState = .pendingEmailVerification - } else { - emailAuthState = .signIn - } - } } struct EmailAuthView: View { @@ -70,8 +59,5 @@ struct EmailAuthView: View { } } } - .task { - viewModel.loadAuthState() - } } } diff --git a/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailSignupFormView.swift b/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailSignupFormView.swift index ff62bd52d..c3c66706d 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailSignupFormView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Registration/EmailAuth/EmailSignupFormView.swift @@ -9,7 +9,6 @@ extension EmailAuthViewModel { func signUp( email: String, password: String, - username: String, fullName: String, authenticator: Authenticator ) async { @@ -17,7 +16,7 @@ extension EmailAuthViewModel { try await authenticator.submitUserSignUp( email: email, password: password, - username: username, + username: potentialUsername, name: fullName ) emailAuthState = .pendingEmailVerification @@ -170,7 +169,6 @@ struct EmailSignupFormView: View { await viewModel.signUp( email: email, password: password, - username: username, fullName: name, authenticator: authenticator ) diff --git a/apple/OmnivoreKit/Sources/Services/Authentication/AccountCreator.swift b/apple/OmnivoreKit/Sources/Services/Authentication/AccountCreator.swift index 140ff5a4c..73e31dbb7 100644 --- a/apple/OmnivoreKit/Sources/Services/Authentication/AccountCreator.swift +++ b/apple/OmnivoreKit/Sources/Services/Authentication/AccountCreator.swift @@ -56,7 +56,8 @@ public extension Authenticator { let params = EmailSignInParams(email: email, password: password) let emailAuthPayload = try await networker.submitEmailLogin(params: params) - if let authPayload = emailAuthPayload.authPayload { + if let authCookieString = emailAuthPayload.authCookieString, let authToken = emailAuthPayload.authToken { + let authPayload = AuthPayload(authCookieString: authCookieString, authToken: authToken) try ValetKey.authCookieString.setValue(authPayload.commentedAuthCookieString) try ValetKey.authToken.setValue(authPayload.authToken) DispatchQueue.main.async { @@ -81,8 +82,7 @@ public extension Authenticator { ) async throws { do { let params = EmailSignUpParams(email: email, password: password, username: username, name: name) - let authPayload = try await networker.submitEmailSignUp(params: params) - try ValetKey.authTokenWithPendingEmail.setValue(authPayload.pendingEmailVerificationToken) + try await networker.submitEmailSignUp(params: params) } catch { let serverError = (error as? ServerError) ?? ServerError.unknown throw LoginError.make(serverError: serverError) diff --git a/apple/OmnivoreKit/Sources/Services/Authentication/AuthModels.swift b/apple/OmnivoreKit/Sources/Services/Authentication/AuthModels.swift index e20acb7f1..454e06b1e 100644 --- a/apple/OmnivoreKit/Sources/Services/Authentication/AuthModels.swift +++ b/apple/OmnivoreKit/Sources/Services/Authentication/AuthModels.swift @@ -41,7 +41,8 @@ struct AuthPayload: Decodable { } struct EmailAuthPayload: Decodable { - let authPayload: AuthPayload? + let authCookieString: String? + let authToken: String? let pendingEmailVerification: Bool? } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Networking/ServerResources/VerifyAuthProviderToken.swift b/apple/OmnivoreKit/Sources/Services/DataService/Networking/ServerResources/VerifyAuthProviderToken.swift index c469dd955..0a2e4e4d7 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Networking/ServerResources/VerifyAuthProviderToken.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Networking/ServerResources/VerifyAuthProviderToken.swift @@ -62,7 +62,7 @@ extension Networker { } } - func submitEmailSignUp(params: EmailSignUpParams) async throws -> PendingEmailVerificationAuthPayload { + func submitEmailSignUp(params: EmailSignUpParams) async throws { let encodedParams = (try? JSONEncoder().encode(params)) ?? Data() let urlRequest = URLRequest.create( @@ -71,13 +71,13 @@ extension Networker { requestMethod: .post(params: encodedParams) ) - let resource = ServerResource( + let resource = ServerResource( urlRequest: urlRequest, - decode: PendingEmailVerificationAuthPayload.decode + decode: EmptyResponse.decode ) do { - return try await urlSession.performRequest(resource: resource) + _ = try await urlSession.performRequest(resource: resource) } catch { if let error = error as? ServerError { throw LoginError.make(serverError: error) diff --git a/apple/OmnivoreKit/Sources/Services/Keychain/ValetKey.swift b/apple/OmnivoreKit/Sources/Services/Keychain/ValetKey.swift index 752279604..e4daea999 100644 --- a/apple/OmnivoreKit/Sources/Services/Keychain/ValetKey.swift +++ b/apple/OmnivoreKit/Sources/Services/Keychain/ValetKey.swift @@ -10,15 +10,10 @@ public enum PublicValet { public static var authToken: String? { ValetKey.authToken.value() } - - public static var hasPendingEmailVerificationToken: Bool { - ValetKey.authTokenWithPendingEmail.exists - } } enum ValetKey: String { case authToken = "app.omnivore.valet.auth-token" - case authTokenWithPendingEmail = "app.omnivore.valet.auth-token-with-pending-email" case authCookieString = "app.omnivore.valet.auth-cookie-raw-string" case appEnvironmentString = "app.omnivore.valet.app-environment" }