Skip to content

Commit

Permalink
🔧 코드 리뷰 반영 로그인 처리 메서드화
Browse files Browse the repository at this point in the history
  • Loading branch information
loinsir committed Dec 11, 2023
1 parent a7be9c5 commit be62bcd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
9 changes: 9 additions & 0 deletions iOS/Layover/Layover/Network/AuthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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
Expand Down
18 changes: 8 additions & 10 deletions iOS/Layover/Layover/Scenes/Login/LoginWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -118,11 +117,10 @@ extension LoginWorker: LoginWorkerProtocol {
let endPoint: EndPoint = loginEndPointFactory.makeAppleLoginEndPoint(with: identityToken)
let result: EndPoint<Response<LoginDTO>>.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)
Expand Down
18 changes: 8 additions & 10 deletions iOS/Layover/Layover/Scenes/SignUpScene/SignUpWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit be62bcd

Please sign in to comment.