Skip to content

Commit

Permalink
feat: 삭제로직 임시 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
mooyoung2309 committed Nov 6, 2023
1 parent b89b4c8 commit 9e0c2e2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Targets/D3N/Sources/App/RootApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct RootApp: App {
WindowGroup {
RootView(
store: Store(initialState: RootStore.State()) {
RootStore()
RootStore()._printChanges()
}
)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
Expand Down
2 changes: 2 additions & 0 deletions Targets/D3N/Sources/App/RootStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct RootStore: Reducer {
}

enum Action: Equatable {
case onAppear

case onboarding(OnboardingNavigationStackStore.Action)
case mainTab(MainTabStore.Action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

public struct LocalStorageManager {
public enum Key: String {
public enum Key: String, CaseIterable {
case accessToken
case refreshToken
case isOnBoardingNeeded
Expand All @@ -23,4 +23,10 @@ public struct LocalStorageManager {
let value = UserDefaults.standard.object(forKey: key.rawValue) as? T
return value
}

public static func deleteAll() {
Key.allCases.forEach { key in
UserDefaults.standard.removeObject(forKey: key.rawValue)
}
}
}
15 changes: 12 additions & 3 deletions Targets/D3N/Sources/Domain/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Moya

struct AuthClient {
var appleLogin: (_ code: String, _ idToken: String) async -> Result<AuthEntity, D3NAPIError>
var appleUnlink: () async -> Result<AuthEntity, Error>
var appleUnlink: () async -> Result<Bool, D3NAPIError>
var refresh: () async -> Result<AuthEntity, Error>
}

Expand All @@ -22,7 +22,7 @@ extension AuthClient: TestDependencyKey {
appleLogin: { code, idToken in
return .success(.init(accessToken: "", refreshToken: ""))
},
appleUnlink: { .init(.success(.init(accessToken: "", refreshToken: ""))) },
appleUnlink: { .success(.init(true)) },
refresh: { .init(.success(.init(accessToken: "", refreshToken: ""))) }
)

Expand Down Expand Up @@ -54,11 +54,20 @@ extension AuthClient: DependencyKey {
}
},
appleUnlink: {
return .success(.init(accessToken: "", refreshToken: ""))
let target: TargetType = AuthService.appleUnlink
let response: Result<EmptyDTO, D3NAPIError> = await D3NAPIkProvider.reqeust(target: target)

LocalStorageManager.deleteAll()

return response.map { dto in
LocalStorageManager.deleteAll()
return true
}
},
refresh: {
return .success(.init(accessToken: "", refreshToken: ""))
}
)
}

public struct EmptyDTO: Codable {}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public struct OnboardingNavigationStackStore: Reducer {
switch action {
case let .submit(newsFields):
state.newsFields = newsFields
return .none
return .send(.userOnboardRequest)
}

case .userOnboardNeededRequest:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ public struct TodayNavigationStackStore: Reducer {
}
}

@Dependency(\.authClient) var authClient

public var body: some ReducerOf<Self> {
BindingReducer()

Reduce { state, action in
switch action {
case .onAppear:
return .none
return .run { send in
await authClient.appleUnlink()
}
// return .none

case let .main(.delegate(action)):
switch action {
Expand Down

0 comments on commit 9e0c2e2

Please sign in to comment.