-
Notifications
You must be signed in to change notification settings - Fork 0
로그인 게이트 UI와 라우팅 추가 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
111 changes: 111 additions & 0 deletions
111
Projects/Feature/Sources/Scene/Login/LoginFeature.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import Domain | ||
| import Foundation | ||
| import ThirdParty | ||
|
|
||
| @Reducer | ||
| public struct LoginFeature { | ||
| @ObservableState | ||
| public struct State: Equatable { | ||
| public var isLoading = false | ||
| public var errorMessage: String? | ||
|
|
||
| public init( | ||
| isLoading: Bool = false, | ||
| errorMessage: String? = nil | ||
| ) { | ||
| self.isLoading = isLoading | ||
| self.errorMessage = errorMessage | ||
| } | ||
| } | ||
|
|
||
| public enum Action: Equatable { | ||
| case onAppear | ||
| case kakaoLoginTapped | ||
| case appleLoginTapped | ||
| case loginResponse(Result<AuthSession, AuthError>) | ||
| case delegate(Delegate) | ||
|
|
||
| public enum Delegate: Equatable { | ||
| case loggedIn(AuthSession) | ||
| } | ||
| } | ||
|
|
||
| @Dependency(\.authClient) var authClient | ||
|
|
||
| public init() {} | ||
|
|
||
| public var body: some ReducerOf<Self> { | ||
| Reduce { state, action in | ||
| switch action { | ||
| case .onAppear: | ||
| return .none | ||
|
|
||
| case .kakaoLoginTapped: | ||
| return login(state: &state, provider: .kakao) | ||
|
|
||
| case .appleLoginTapped: | ||
| return login(state: &state, provider: .apple) | ||
|
|
||
| case let .loginResponse(.success(session)): | ||
| state.isLoading = false | ||
| state.errorMessage = nil | ||
| return .send(.delegate(.loggedIn(session))) | ||
|
|
||
| case let .loginResponse(.failure(error)): | ||
| state.isLoading = false | ||
| // 사용자 취소는 에러 메시지 없이 idle 복귀한다. | ||
| if case .cancelled = error { | ||
| state.errorMessage = nil | ||
| } else { | ||
| state.errorMessage = Self.errorMessage(for: error) | ||
| } | ||
| return .none | ||
|
|
||
| case .delegate: | ||
| return .none | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func login( | ||
| state: inout State, | ||
| provider: AuthProvider | ||
| ) -> Effect<Action> { | ||
| guard state.isLoading == false else { | ||
| return .none | ||
| } | ||
|
|
||
| state.isLoading = true | ||
| state.errorMessage = nil | ||
|
|
||
| return .run { [authClient] send in | ||
| do { | ||
| let session = try await authClient.login(provider) | ||
| await send(.loginResponse(.success(session))) | ||
| } catch let error as AuthError { | ||
| await send(.loginResponse(.failure(error))) | ||
| } catch { | ||
| await send(.loginResponse(.failure(.unknown(message: error.localizedDescription)))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static func errorMessage(for error: AuthError) -> String { | ||
| switch error { | ||
| case .cancelled: | ||
| return "" | ||
| case .notConfigured: | ||
| return "로그인 설정이 완료되지 않았어요." | ||
| case .loginFailed: | ||
| return "로그인에 실패했어요" | ||
| case .network: | ||
| return "네트워크 연결을 확인해 주세요" | ||
| case .unauthorized: | ||
| return "로그인에 실패했어요" | ||
| case .storage: | ||
| return "로그인 정보를 저장하지 못했어요." | ||
| case .unknown: | ||
| return "알 수 없는 오류가 발생했어요." | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.