-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] 로그아웃, 회원탈퇴(초안) 구현 #38
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // | ||
| // MyPageView.swift | ||
| // Mark-In | ||
| // | ||
| // Created by 이정동 on 5/13/25. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| import DesignSystem | ||
|
|
||
| private enum ViewConstants { | ||
| static let minContentWidth: CGFloat = 164 | ||
| } | ||
|
|
||
| struct MyPageView: View { | ||
| @State private var viewModel = MyPageViewModel() | ||
| @State private var contentWidth = ViewConstants.minContentWidth | ||
|
|
||
| var body: some View { | ||
| VStack(spacing: 30) { | ||
| headerTitle | ||
| .padding(.top, 16) | ||
|
|
||
| footerButtons | ||
| .padding(.bottom, 12) | ||
| } | ||
| .frame(width: contentWidth) | ||
| } | ||
|
|
||
| private var headerTitle: some View { | ||
| VStack(spacing: 2) { | ||
| Text("User Name") | ||
| .font(.pretendard(size: 14, weight: .semiBold)) | ||
| .foregroundStyle(.markBlack) | ||
|
|
||
| Text("asdfasdfasdf012345@gmail.com") | ||
| .font(.pretendard(size: 10, weight: .regular)) | ||
| .tint(.markBlack) | ||
| .fixedSize() | ||
| .padding(.horizontal, 8) | ||
| .background( | ||
| GeometryReader { geo in | ||
| Color.clear | ||
| .onAppear { | ||
| let width = geo.size.width | ||
| contentWidth = max(width, ViewConstants.minContentWidth) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private var footerButtons: some View { | ||
| VStack(spacing: 8) { | ||
| Button { | ||
| viewModel.send(.logoutButtonTapped) | ||
| } label: { | ||
| Text("로그아웃") | ||
| .font(.pretendard(size: 12, weight: .regular)) | ||
| .foregroundStyle(.markBlack) | ||
| } | ||
|
|
||
| Divider() | ||
| .padding(.horizontal, 8) | ||
|
|
||
| Button { | ||
| viewModel.send(.withdrawalButtonTapped) | ||
| } label: { | ||
| Text("회원 탈퇴") | ||
| .font(.pretendard(size: 12, weight: .regular)) | ||
| .foregroundStyle(.markRed) | ||
| } | ||
| } | ||
| .buttonStyle(.plain) | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| MyPageView() | ||
| } |
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,115 @@ | ||
| // | ||
| // MyPageViewModel.swift | ||
| // Mark-In | ||
| // | ||
| // Created by 이정동 on 5/13/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| import FirebaseAuth | ||
| import GoogleSignIn | ||
|
|
||
| @Observable | ||
| final class MyPageViewModel: Reducer { | ||
| struct State { | ||
| var userState: AuthUserState = .init() | ||
| } | ||
|
|
||
| enum Action { | ||
| case logoutButtonTapped | ||
| case withdrawalButtonTapped | ||
|
|
||
| case didSuccessLogout | ||
| case didFailLogout | ||
|
|
||
| case didSuccessWithdrawal | ||
| case didFailWithdrawal | ||
| } | ||
|
|
||
| private let authUserManager: AuthUserManager | ||
|
|
||
| private(set) var state: State = .init() | ||
|
|
||
| init() { | ||
| self.authUserManager = DIContainer.shared.resolve() | ||
| } | ||
|
|
||
| func send(_ action: Action) { | ||
| let effect = reduce(state: &state, action: action) | ||
| handleEffect(effect) | ||
| } | ||
|
|
||
| func reduce(state: inout State, action: Action) -> Effect<Action> { | ||
| switch action { | ||
| case .logoutButtonTapped: | ||
| return .run { | ||
| // TODO: 이후 Auth 모듈로 분리하면서 코드 리팩토링 예정 | ||
| do { | ||
| try Auth.auth().signOut() | ||
|
|
||
| if GIDSignIn.sharedInstance.currentUser != nil { | ||
| GIDSignIn.sharedInstance.signOut() | ||
| } | ||
| return .didSuccessLogout | ||
| } catch { | ||
| return .didFailLogout | ||
| } | ||
| } | ||
|
|
||
| case .withdrawalButtonTapped: | ||
| return .run { | ||
| // TODO: 이후 Auth 모듈로 분리하면서 코드 리팩토링 예정 | ||
| do { | ||
| // TODO: 재인증 과정 필요 | ||
| // try await Auth.auth().currentUser?.reauthenticate(with: credential) | ||
| try await Auth.auth().currentUser?.delete() | ||
|
|
||
| if GIDSignIn.sharedInstance.currentUser != nil { | ||
| try await GIDSignIn.sharedInstance.disconnect() | ||
| GIDSignIn.sharedInstance.signOut() | ||
| } | ||
|
|
||
| return .didSuccessWithdrawal | ||
| } catch { | ||
| return .didFailWithdrawal | ||
| } | ||
| } | ||
|
|
||
| case .didSuccessLogout: | ||
| authUserManager.clear() | ||
| return .none | ||
|
|
||
| // TODO: 로그아웃 실패에 대한 처리 필요 | ||
| case .didFailLogout: | ||
| return .none | ||
|
|
||
| case .didSuccessWithdrawal: | ||
| authUserManager.clear() | ||
| return .none | ||
|
|
||
| // TODO: 회원탈퇴 실패에 대한 처리 필요 | ||
| case .didFailWithdrawal: | ||
| return .none | ||
| } | ||
| } | ||
|
|
||
| private func handleEffect(_ effect: Effect<Action>) { | ||
| switch effect { | ||
| case .none: | ||
| break | ||
| case .run(let action): | ||
| Task.detached { [weak self] in | ||
| let newAction = await action() | ||
| await self?.send(newAction) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension MyPageViewModel { | ||
| struct AuthUserState { | ||
| var name: String = "" | ||
| var email: String = "" | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DIContainer를 shared로 사용하는건가요?