Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #193 - 액세스 토큰 만료 로직 구현 #207

Merged
merged 7 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
09582B5129C0BC3600EF3207 /* DetailAchievementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09582B5029C0BC3600EF3207 /* DetailAchievementViewController.swift */; };
0960C0D42A38BC6500A3D8DB /* KeychainUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0960C0D32A38BC6500A3D8DB /* KeychainUtil.swift */; };
0960C0D62A38BC8100A3D8DB /* DefaultKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0960C0D52A38BC8100A3D8DB /* DefaultKeys.swift */; };
0964BA4A2B0F6BFB00A8984B /* AuthInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0964BA492B0F6BFB00A8984B /* AuthInterceptor.swift */; };
097568362A2FEF630001EC46 /* String+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 097568352A2FEF3F0001EC46 /* String+.swift */; };
097C003629AB8270008CAEF3 /* MissionListCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 097C003529AB8270008CAEF3 /* MissionListCollectionViewCell.swift */; };
0982DE5429ADCCE000D933D2 /* HomeEmptyCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0982DE5329ADCCE000D933D2 /* HomeEmptyCollectionViewCell.swift */; };
Expand Down Expand Up @@ -188,6 +189,7 @@
09582B5029C0BC3600EF3207 /* DetailAchievementViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailAchievementViewController.swift; sourceTree = "<group>"; };
0960C0D32A38BC6500A3D8DB /* KeychainUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainUtil.swift; sourceTree = "<group>"; };
0960C0D52A38BC8100A3D8DB /* DefaultKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultKeys.swift; sourceTree = "<group>"; };
0964BA492B0F6BFB00A8984B /* AuthInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthInterceptor.swift; sourceTree = "<group>"; };
097568352A2FEF3F0001EC46 /* String+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+.swift"; sourceTree = "<group>"; };
097C003529AB8270008CAEF3 /* MissionListCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissionListCollectionViewCell.swift; sourceTree = "<group>"; };
0982DE5329ADCCE000D933D2 /* HomeEmptyCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeEmptyCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1039,6 +1041,7 @@
isa = PBXGroup;
children = (
6CF4705A29A68EA9008D145C /* URLConstant.swift */,
0964BA492B0F6BFB00A8984B /* AuthInterceptor.swift */,
6CF4705C29A68F5C008D145C /* NetworkLoggerPlugin.swift */,
6CF4705E29A69025008D145C /* GeneralResponse.swift */,
6CF4706029A69096008D145C /* NetworkConstant.swift */,
Expand Down Expand Up @@ -1307,6 +1310,7 @@
09582B4829BDA7F600EF3207 /* DetailStackView.swift in Sources */,
09F6718429CADB1100708725 /* OnboardingModel.swift in Sources */,
3B027A7A299C31B500BEB65C /* SceneDelegate.swift in Sources */,
0964BA4A2B0F6BFB00A8984B /* AuthInterceptor.swift in Sources */,
09582B5129C0BC3600EF3207 /* DetailAchievementViewController.swift in Sources */,
0982DE5829AE40FB00D933D2 /* UITabBar+.swift in Sources */,
3BC1A27929C9BE6C0088376B /* AddMissionFooterCollectionReusableView.swift in Sources */,
Expand Down
27 changes: 20 additions & 7 deletions iOS-NOTTODO/iOS-NOTTODO/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import UIKit
import KakaoSDKAuth

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
static var shared: SceneDelegate? { UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate }

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.overrideUserInterfaceStyle = UIUserInterfaceStyle.light

let rootViewController = ValueOnboardingViewController()
let navigationController = UINavigationController(rootViewController: rootViewController)
navigationController.isNavigationBarHidden = true
Expand All @@ -33,19 +34,31 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
}
}

func sceneDidDisconnect(_ scene: UIScene) {
}

func sceneDidBecomeActive(_ scene: UIScene) {
}

func sceneWillResignActive(_ scene: UIScene) {
}

func sceneWillEnterForeground(_ scene: UIScene) {
}

func sceneDidEnterBackground(_ scene: UIScene) {
}
}

extension SceneDelegate {

func changeRootViewControllerTo(_ viewController: UIViewController) {
guard let window = window else { return }

let rootViewController = viewController
let navigationController = UINavigationController(rootViewController: rootViewController)
navigationController.isNavigationBarHidden = true
window.rootViewController = navigationController
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class AchieveAPI {

static let shared: AchieveAPI = AchieveAPI()

private let achieveProvider = MoyaProvider<AchieveService>(plugins: [MoyaLoggingPlugin()])
private let achieveProvider = MoyaProvider<AchieveService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])

private init() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class AddMissionAPI {

static let shared: AddMissionAPI = AddMissionAPI()

private let addMissionProvider = MoyaProvider<AddMissionService>(plugins: [MoyaLoggingPlugin()])
private let addMissionProvider = MoyaProvider<AddMissionService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])

private init() { }

Expand Down
2 changes: 1 addition & 1 deletion iOS-NOTTODO/iOS-NOTTODO/Network/API/Auth/AuthAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class AuthAPI {

static let shared: AuthAPI = AuthAPI()

private let authProvider = MoyaProvider<AuthService>(plugins: [MoyaLoggingPlugin()])
private let authProvider = MoyaProvider<AuthService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])

private init() { }

Expand Down
2 changes: 1 addition & 1 deletion iOS-NOTTODO/iOS-NOTTODO/Network/API/Home/HomeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class HomeAPI {

static let shared: HomeAPI = HomeAPI()

var homeProvider = MoyaProvider<HomeService>(plugins: [MoyaLoggingPlugin()])
var homeProvider = MoyaProvider<HomeService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])

private init() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class RecommendAPI {

static let shared: RecommendAPI = RecommendAPI()

private let recommendProvider = MoyaProvider<RecommendService>(plugins: [MoyaLoggingPlugin()])
private let recommendProvider = MoyaProvider<RecommendService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])

private init() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class RecommendActionAPI {

static let shared: RecommendActionAPI = RecommendActionAPI()

private let recommendActionProvider = MoyaProvider<RecommendActionService>(plugins: [MoyaLoggingPlugin()])
private let recommendActionProvider = MoyaProvider<RecommendActionService>(session: Session(interceptor: AuthInterceptor.shared), plugins: [MoyaLoggingPlugin()])

private init() { }

Expand Down
30 changes: 30 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Network/Base/AuthInterceptor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// AuthInterceptor.swift
// iOS-NOTTODO
//
// Created by JEONGEUN KIM on 11/23/23.
//

import Foundation

import Alamofire

final class AuthInterceptor: RequestInterceptor {

static let shared = AuthInterceptor()

private init() {}

func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {

guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401
else {
completion(.doNotRetry)
return
}

DispatchQueue.main.async {
SceneDelegate.shared?.changeRootViewControllerTo(AuthViewController())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 김민서 on 2023/02/23.
//

import Foundation
import UIKit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIKit도 이제 없어두 될거 같아여!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹!
db4086c


import Moya

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ extension AchieveService: TargetType {
}
}

var validationType: ValidationType {
return .successCodes
}

var task: Moya.Task {
switch self {
case .achieveCalendar, .achieveDetail:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ extension AddMissionService: TargetType {
}
}

var validationType: ValidationType {
return .successCodes
}

var task: Moya.Task {
switch self {
case .recommendSituation, .recentMission, .missionDates:
Expand All @@ -64,7 +68,7 @@ extension AddMissionService: TargetType {
encoding: JSONEncoding.default)
}
}

var headers: [String: String]? {
switch self {
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ extension AuthService: TargetType {
return .delete
}
}

var validationType: ValidationType {
return .successCodes
}

var task: Moya.Task {
switch self {
case .kakaoAuth(_, let socialToken, let fcmToken):
Expand Down
4 changes: 4 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Network/Service/Home/HomeSevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ extension HomeService: TargetType {
}
}

var validationType: ValidationType {
return .successCodes
}

var task: Moya.Task {
switch self {
case .dailyMission, .deleteMission, .missionWeekly, .dailyDetailMission, .particularMission:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extension RecommendActionService: TargetType {
}
}

var validationType: ValidationType {
return .successCodes
}

var task: Moya.Task {
switch self {
case .recommendAction:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extension RecommendService: TargetType {
}
}

var validationType: ValidationType {
return .successCodes
}

var task: Moya.Task {
switch self {
case .recommend:
Expand Down