Skip to content

Commit

Permalink
Merge branch 'develop' into Application/504_XWebKit-version-up
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeong525 authored May 29, 2023
2 parents 91470a0 + 7ccbea0 commit becbc14
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Services/AuthService/Sources/DI/AuthServiceDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ extension AuthServiceDependency {
static func resolve() -> AuthServiceDependency {
// MARK: - Datasources
let remoteAuthDataSource: RemoteAuthDataSource = RemoteAuthDataSourceImpl()
let loaclTokenDataSource: LoaclTokenDataSource = LoaclTokenDataSourceImpl()
let localTokenDataSource: LocalTokenDataSource = LocalTokenDataSourceImpl()
let localAuthDataSource: LocalAuthDataSource = LocalAuthDataSourceImpl()

// MARK: - Respositories
let authRepository: AuthRepository = AuthRepositoryImpl(
remoteAuthDataSource: remoteAuthDataSource,
loaclTokenDataSource: loaclTokenDataSource,
localTokenDataSource: localTokenDataSource,
localAuthDataSource: localAuthDataSource
)

Expand Down Expand Up @@ -58,7 +58,7 @@ extension AuthServiceDependency {

// MARK: - Plugin
let jwtPlugin = JWTPlugin(
loaclTokenDataSource: loaclTokenDataSource
localTokenDataSource: localTokenDataSource
)

return AuthServiceDependency(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

protocol LoaclTokenDataSource {
protocol LocalTokenDataSource {
func registerAccessToken(_ accessToken: String)
func fetchAccessToken() -> String?
func registerRefreshToken(_ refreshToken: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import XDateUtil
import KeychainModule

class LoaclTokenDataSourceImpl: LoaclTokenDataSource {
class LocalTokenDataSourceImpl: LocalTokenDataSource {

let keychain = KeychainModule<KeychainTypeForAuth>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import RxSwift
class AuthRepositoryImpl: AuthRepository {

private let remoteAuthDataSource: RemoteAuthDataSource
private let loaclTokenDataSource: LoaclTokenDataSource
private let localTokenDataSource: LocalTokenDataSource
private let localAuthDataSource: LocalAuthDataSource

init(remoteAuthDataSource: RemoteAuthDataSource,
loaclTokenDataSource: LoaclTokenDataSource,
localTokenDataSource: LocalTokenDataSource,
localAuthDataSource: LocalAuthDataSource) {
self.remoteAuthDataSource = remoteAuthDataSource
self.loaclTokenDataSource = loaclTokenDataSource
self.localTokenDataSource = localTokenDataSource
self.localAuthDataSource = localAuthDataSource
}

func signin(signinEntity: SigninEntity) -> Completable {
self.remoteAuthDataSource.signin(request: signinEntity.toSigninRequest())
.do(onSuccess: { [weak self] tokenResponse in
self?.loaclTokenDataSource.registerAccessToken(tokenResponse.accessToken)
self?.loaclTokenDataSource.registerRefreshToken(tokenResponse.refreshToken)
self?.loaclTokenDataSource.registerExpiredAt(tokenResponse.expirationAt)
self?.localTokenDataSource.registerAccessToken(tokenResponse.accessToken)
self?.localTokenDataSource.registerRefreshToken(tokenResponse.refreshToken)
self?.localTokenDataSource.registerExpiredAt(tokenResponse.expirationAt)
self?.localAuthDataSource.registerIdAndPassword(id: signinEntity.id, password: signinEntity.password)
}).catch { error in
let moyaError = error as? MoyaError
Expand All @@ -48,14 +48,14 @@ class AuthRepositoryImpl: AuthRepository {
}

func refreshToken() -> Completable {
guard let refershToken = self.loaclTokenDataSource.fetchRefreshToken() else {
guard let refershToken = self.localTokenDataSource.fetchRefreshToken() else {
return Completable.error(AuthServiceError.noToken)
}
return self.remoteAuthDataSource.refreshToken(refreshToken: refershToken)
.do(onSuccess: { [weak self] tokenResponse in
self?.loaclTokenDataSource.registerAccessToken(tokenResponse.accessToken)
self?.loaclTokenDataSource.registerRefreshToken(tokenResponse.refreshToken)
self?.loaclTokenDataSource.registerExpiredAt(tokenResponse.expirationAt)
self?.localTokenDataSource.registerAccessToken(tokenResponse.accessToken)
self?.localTokenDataSource.registerRefreshToken(tokenResponse.refreshToken)
self?.localTokenDataSource.registerExpiredAt(tokenResponse.expirationAt)
}).catch { [weak self] error in
let moyaError = error as? MoyaError
guard moyaError?.response?.statusCode != nil else { return .error(AuthServiceError.networkNotWorking) }
Expand All @@ -68,14 +68,14 @@ class AuthRepositoryImpl: AuthRepository {
}

func fetchAccessToken() throws -> String {
guard let accessToken = self.loaclTokenDataSource.fetchAccessToken() else {
guard let accessToken = self.localTokenDataSource.fetchAccessToken() else {
throw AuthServiceError.noToken
}
return accessToken
}

func fetchTokenExpiredDate() throws -> Date {
guard let expiredDate = self.loaclTokenDataSource.fetchExpiredDate() else {
guard let expiredDate = self.localTokenDataSource.fetchExpiredDate() else {
throw AuthServiceError.noToken
}
return expiredDate
Expand All @@ -91,7 +91,7 @@ class AuthRepositoryImpl: AuthRepository {

func logout() -> Completable {
Completable.create { completable in
self.loaclTokenDataSource.resetToken()
self.localTokenDataSource.resetToken()
completable(.completed)
return Disposables.create()
}
Expand Down
10 changes: 5 additions & 5 deletions Services/AuthService/Sources/Plugin/JWTPulgin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public enum JWTTokenType {
// MARK: - JWTPlugin
final public class JWTPlugin: PluginType {

private let loaclTokenDataSource: LoaclTokenDataSource
private let localTokenDataSource: LocalTokenDataSource

init(loaclTokenDataSource: LoaclTokenDataSource) {
self.loaclTokenDataSource = loaclTokenDataSource
init(localTokenDataSource: LocalTokenDataSource) {
self.localTokenDataSource = localTokenDataSource
}

public func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
Expand Down Expand Up @@ -68,11 +68,11 @@ extension JWTPlugin {
}

private func fetchAccessToken() -> String? {
self.loaclTokenDataSource.fetchAccessToken()
self.localTokenDataSource.fetchAccessToken()
}

private func fetchRefreshToken() -> String? {
self.loaclTokenDataSource.fetchRefreshToken()
self.localTokenDataSource.fetchRefreshToken()
}

}

0 comments on commit becbc14

Please sign in to comment.