@@ -9,6 +9,9 @@ protocol AuthServicing {
99
1010 @MainActor
1111 func loginWithApple( ) async throws -> AppleAuthPayload
12+
13+ @MainActor
14+ func loginWithTester( ) async throws -> AuthLoginResponse
1215}
1316
1417struct AppleAuthPayload {
@@ -29,6 +32,7 @@ enum AuthServiceError: LocalizedError {
2932 case missingAppleAuthorizationCode
3033 case invalidAppleIdentityTokenEncoding
3134 case invalidAppleAuthorizationCodeEncoding
35+ case testLoginFailed( underlying: Error )
3236
3337 var errorDescription : String ? {
3438 switch self {
@@ -50,6 +54,16 @@ enum AuthServiceError: LocalizedError {
5054 return " 애플 authorization code를 가져오지 못했어요. "
5155 case . invalidAppleIdentityTokenEncoding, . invalidAppleAuthorizationCodeEncoding:
5256 return " 애플 로그인 인증값 인코딩에 실패했어요. "
57+ case . testLoginFailed( let underlying) :
58+ if
59+ let apiError = underlying as? APIClientError ,
60+ case . serverError( _, let message) = apiError,
61+ let message,
62+ !message. isEmpty
63+ {
64+ return message
65+ }
66+ return " 체험하기 로그인에 실패했어요. 다시 시도해 주세요. "
5367 }
5468 }
5569}
@@ -58,6 +72,17 @@ final class AuthService: NSObject, AuthServicing {
5872 private var appleLoginContinuation : CheckedContinuation < AppleAuthPayload , Error > ?
5973 private var applePresentationAnchor : ASPresentationAnchor ?
6074 private var appleAuthorizationController : ASAuthorizationController ?
75+ private let apiClient : APIClienting
76+ private let tokenStore : TokenStoring
77+
78+ init (
79+ apiClient: APIClienting = APIClient . shared,
80+ tokenStore: TokenStoring = TokenStore . shared
81+ ) {
82+ self . apiClient = apiClient
83+ self . tokenStore = tokenStore
84+ super. init ( )
85+ }
6186
6287 func loginWithKakao( ) async throws -> String {
6388 let appKey = ( Bundle . main. object ( forInfoDictionaryKey: " KAKAO_NATIVE_APP_KEY " ) as? String ?? " " )
@@ -93,6 +118,29 @@ final class AuthService: NSObject, AuthServicing {
93118 }
94119 }
95120
121+ func loginWithTester( ) async throws -> AuthLoginResponse {
122+ do {
123+ let request = APIRequest (
124+ path: " /oauth2/test " ,
125+ method: . get,
126+ requiresAuthorization: false
127+ )
128+ let response = try await apiClient. request (
129+ request,
130+ responseType: AuthLoginResponse . self
131+ )
132+ let normalizedResponse = response. withIsNew ( true )
133+
134+ tokenStore. save (
135+ accessToken: normalizedResponse. accessToken,
136+ refreshToken: normalizedResponse. refreshToken
137+ )
138+ return normalizedResponse
139+ } catch {
140+ throw AuthServiceError . testLoginFailed ( underlying: error)
141+ }
142+ }
143+
96144 private func loginWithKakaoTalk( ) async throws -> String {
97145 try await withCheckedThrowingContinuation { continuation in
98146 UserApi . shared. loginWithKakaoTalk { oauthToken, error in
0 commit comments