diff --git a/SodaLive/Sources/Chat/ChatTabView.swift b/SodaLive/Sources/Chat/ChatTabView.swift index a031681..c07fd41 100644 --- a/SodaLive/Sources/Chat/ChatTabView.swift +++ b/SodaLive/Sources/Chat/ChatTabView.swift @@ -14,6 +14,8 @@ struct ChatTabView: View { @AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token) @AppStorage("auth") private var auth: Bool = UserDefaults.bool(forKey: UserDefaultsKey.auth) + @StateObject var mypageViewModel = MyPageViewModel() + private enum InnerTab: Int, CaseIterable { case character = 0 case original = 1 @@ -153,12 +155,15 @@ struct ChatTabView: View { AppState.shared.isShowErrorPopup = true isShowAuthView = false } - .onDone { _ in - auth = true - isShowAuthView = false - if let action = pendingAction { - pendingAction = nil - action() + .onDone { + DEBUG_LOG("onDone: \($0)") + mypageViewModel.authVerify($0) { + auth = true + isShowAuthView = false + if let action = pendingAction { + pendingAction = nil + action() + } } } .onClose { diff --git a/SodaLive/Sources/Home/HomeTabView.swift b/SodaLive/Sources/Home/HomeTabView.swift index 063e2c4..eb84705 100644 --- a/SodaLive/Sources/Home/HomeTabView.swift +++ b/SodaLive/Sources/Home/HomeTabView.swift @@ -12,6 +12,7 @@ import BootpayUI struct HomeTabView: View { @StateObject var viewModel = HomeTabViewModel() @StateObject var liveViewModel = LiveViewModel() + @StateObject var mypageViewModel = MyPageViewModel() @AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token) @AppStorage("role") private var role: String = UserDefaults.string(forKey: UserDefaultsKey.role) @@ -460,12 +461,15 @@ struct HomeTabView: View { AppState.shared.isShowErrorPopup = true isShowAuthView = false } - .onDone { _ in - auth = true - isShowAuthView = false - if let action = pendingAction { - pendingAction = nil - action() + .onDone { + DEBUG_LOG("onDone: \($0)") + mypageViewModel.authVerify($0) { + auth = true + isShowAuthView = false + if let action = pendingAction { + pendingAction = nil + action() + } } } .onClose { diff --git a/SodaLive/Sources/MyPage/MyPageViewModel.swift b/SodaLive/Sources/MyPage/MyPageViewModel.swift index 64b8377..5292fa3 100644 --- a/SodaLive/Sources/MyPage/MyPageViewModel.swift +++ b/SodaLive/Sources/MyPage/MyPageViewModel.swift @@ -72,7 +72,7 @@ final class MyPageViewModel: ObservableObject { .store(in: &subscription) } - func authVerify(_ data: [String: Any]) { + func authVerify(_ data: [String: Any], onSuccess: (() -> Void)? = nil) { isLoading = true let _data = data["data"] as? [String: Any] @@ -102,8 +102,13 @@ final class MyPageViewModel: ObservableObject { } else { UserDefaults.set(ContentType.MALE.rawValue, forKey: .contentPreference) } - AppState.shared.isRestartApp = true - AppState.shared.setAppStep(step: .splash) + + if let onSuccess = onSuccess { + onSuccess() + } else { + AppState.shared.isRestartApp = true + AppState.shared.setAppStep(step: .splash) + } } else { if let message = decoded.message { self.errorMessage = message