Skip to content

Commit

Permalink
[chore] #84 회원탈퇴 및 로그아웃 액션 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
stealmh committed Aug 9, 2024
1 parent b5fce87 commit 4758aa6
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public struct PokitSettingFeature {
case 회원탈퇴_팝업(isPresented: Bool)
}

public enum AsyncAction: Equatable { case doNothing }
public enum AsyncAction: Equatable {
case 회원탈퇴_네트워크
case 키_제거
}

public enum ScopeAction: Equatable {
case doNothing
Expand Down Expand Up @@ -144,6 +147,7 @@ private extension PokitSettingFeature {

case .로그아웃수행:
return .run { send in
await send(.async(.키_제거))
await send(.inner(.로그아웃_팝업(isPresented: false)))
await send(.delegate(.로그아웃))
}
Expand All @@ -153,16 +157,8 @@ private extension PokitSettingFeature {

case .회원탈퇴수행:
return .run { send in
guard let refreshToken = keychain.read(.refreshToken) else { return }
guard let platform = userDefaults.stringKey(.authPlatform) else { return }

let request = WithdrawRequest(refreshToken: refreshToken, authPlatform: platform)
try await authClient.회원탈퇴(request)

keychain.delete(.accessToken)
keychain.delete(.refreshToken)
await userDefaults.removeString(.authPlatform)

await send(.async(.회원탈퇴_네트워크))
await send(.async(.키_제거))
await send(.inner(.회원탈퇴_팝업(isPresented: false)))
await send(.delegate(.회원탈퇴))
}
Expand Down Expand Up @@ -195,7 +191,21 @@ private extension PokitSettingFeature {

/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
return .none
switch action {
case .회원탈퇴_네트워크:
return .run { _ in
guard let refreshToken = keychain.read(.refreshToken) else { return }
guard let platform = userDefaults.stringKey(.authPlatform) else { return }

let request = WithdrawRequest(refreshToken: refreshToken, authPlatform: platform)
try await authClient.회원탈퇴(request)
}

case .키_제거:
keychain.delete(.accessToken)
keychain.delete(.refreshToken)
return .run { _ in await userDefaults.removeString(.authPlatform) }
}
}

/// - Scope Effect
Expand Down

0 comments on commit 4758aa6

Please sign in to comment.