diff --git a/iOS/Layover/Layover/Network/AuthManager.swift b/iOS/Layover/Layover/Network/AuthManager.swift index d53e975..419e3aa 100644 --- a/iOS/Layover/Layover/Network/AuthManager.swift +++ b/iOS/Layover/Layover/Network/AuthManager.swift @@ -13,6 +13,7 @@ protocol AuthManagerProtocol: AnyObject { var loginType: LoginType? { get set } var memberID: Int? { get set } + func login(accessToken: String?, refreshToken: String?, memberID: Int?, loginType: LoginType?) func logout() } @@ -22,6 +23,14 @@ enum LoginType: String, Codable { } extension AuthManagerProtocol { + func login(accessToken: String?, refreshToken: String?, memberID: Int?, loginType: LoginType?) { + self.accessToken = accessToken + self.refreshToken = refreshToken + self.memberID = memberID + self.loginType = loginType + isLoggedIn = true + } + func logout() { accessToken = nil refreshToken = nil diff --git a/iOS/Layover/Layover/Scenes/Login/LoginWorker.swift b/iOS/Layover/Layover/Scenes/Login/LoginWorker.swift index 059266a..e3a8fcc 100644 --- a/iOS/Layover/Layover/Scenes/Login/LoginWorker.swift +++ b/iOS/Layover/Layover/Scenes/Login/LoginWorker.swift @@ -88,11 +88,10 @@ extension LoginWorker: LoginWorkerProtocol { let endPoint = loginEndPointFactory.makeKakaoLoginEndPoint(with: socialToken) let result = try await provider.request(with: endPoint, authenticationIfNeeded: false) - authManager.accessToken = result.data?.accessToken - authManager.refreshToken = result.data?.refreshToken - authManager.isLoggedIn = true - authManager.loginType = .kakao - authManager.memberID = await fetchMemberId() + authManager.login(accessToken: result.data?.accessToken, + refreshToken: result.data?.refreshToken, + memberID: await fetchMemberId(), + loginType: .kakao) return true } catch { os_log(.error, log: .data, "%@", error.localizedDescription) @@ -118,11 +117,10 @@ extension LoginWorker: LoginWorkerProtocol { let endPoint: EndPoint = loginEndPointFactory.makeAppleLoginEndPoint(with: identityToken) let result: EndPoint>.Response = try await provider.request(with: endPoint, authenticationIfNeeded: false) - authManager.accessToken = result.data?.accessToken - authManager.refreshToken = result.data?.refreshToken - authManager.isLoggedIn = true - authManager.loginType = .apple - authManager.memberID = await fetchMemberId() + authManager.login(accessToken: result.data?.accessToken, + refreshToken: result.data?.refreshToken, + memberID: await fetchMemberId(), + loginType: .apple) return true } catch { os_log(.error, log: .data, "%@", error.localizedDescription) diff --git a/iOS/Layover/Layover/Scenes/SignUpScene/SignUpWorker.swift b/iOS/Layover/Layover/Scenes/SignUpScene/SignUpWorker.swift index 9a5d111..5f0eb90 100644 --- a/iOS/Layover/Layover/Scenes/SignUpScene/SignUpWorker.swift +++ b/iOS/Layover/Layover/Scenes/SignUpScene/SignUpWorker.swift @@ -50,11 +50,10 @@ extension SignUpWorker: SignUpWorkerProtocol { return false } - authManager.accessToken = data.accessToken - authManager.refreshToken = data.refreshToken - authManager.isLoggedIn = true - authManager.loginType = .kakao - authManager.memberID = await fetchMemberId() + authManager.login(accessToken: data.accessToken, + refreshToken: data.refreshToken, + memberID: await fetchMemberId(), + loginType: .kakao) return true } catch { os_log(.error, log: .data, "Failed to sign up with error: %@", error.localizedDescription) @@ -71,11 +70,10 @@ extension SignUpWorker: SignUpWorkerProtocol { os_log(.error, log: .default, "Failed to sign up with error: %@", responseData.message) return false } - authManager.accessToken = data.accessToken - authManager.refreshToken = data.refreshToken - authManager.isLoggedIn = true - authManager.loginType = .apple - authManager.memberID = await fetchMemberId() + authManager.login(accessToken: data.accessToken, + refreshToken: data.refreshToken, + memberID: await fetchMemberId(), + loginType: .apple) return true } catch { os_log(.error, log: .data, "Failed to sign up with error: %@", error.localizedDescription)