From 2109dbd67f6f941b0d907228df56159869d2687f Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Sat, 25 Mar 2023 20:03:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]=20#119=20-=20SignInRouter,=20Dto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 16 ++++++ .../Global/Supports/SceneDelegate.swift | 2 +- .../ResponseDto/SignInResponseDto.swift | 23 ++++++++ .../Network/Dto/SignInDto/SignInDto.swift | 14 +++++ .../Network/Router/AuthRouter.swift | 52 +++++++++++++++++++ .../SignIn/VC/SignInSocialLoginVC.swift | 51 +++++++++++++----- 6 files changed, 145 insertions(+), 13 deletions(-) create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/SignInDto.swift create mode 100644 Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 52b9a2f1..d5f1b2df 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ A3BC2F3F2964706100198261 /* UploadedCourseInfoCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F3E2964706100198261 /* UploadedCourseInfoCVC.swift */; }; A3BC2F4129667A0D00198261 /* NicknameEditorVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F4029667A0D00198261 /* NicknameEditorVC.swift */; }; A3BC2F432966A93100198261 /* CourseDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F422966A93100198261 /* CourseDetailVC.swift */; }; + A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77829CF03D200DD54EC /* AuthRouter.swift */; }; + A3D1A77E29CF09B600DD54EC /* SignInResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */; }; A3E55BA029C815B10000D85D /* SignInSocialLoginVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3E55B9F29C815B10000D85D /* SignInSocialLoginVC.swift */; }; A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE1296D33AC001598A2 /* MyPageDto.swift */; }; A3F67AEA296E4936001598A2 /* ActivityRecordInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */; }; @@ -156,6 +158,8 @@ A3BC2F3E2964706100198261 /* UploadedCourseInfoCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadedCourseInfoCVC.swift; sourceTree = ""; }; A3BC2F4029667A0D00198261 /* NicknameEditorVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameEditorVC.swift; sourceTree = ""; }; A3BC2F422966A93100198261 /* CourseDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailVC.swift; sourceTree = ""; }; + A3D1A77829CF03D200DD54EC /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = ""; }; + A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInResponseDto.swift; sourceTree = ""; }; A3E55B9F29C815B10000D85D /* SignInSocialLoginVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInSocialLoginVC.swift; sourceTree = ""; }; A3E55BA529C8AB0A0000D85D /* Runnect-iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Runnect-iOS.entitlements"; sourceTree = ""; }; A3F67AE1296D33AC001598A2 /* MyPageDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageDto.swift; sourceTree = ""; }; @@ -361,6 +365,14 @@ path = UploadedCourseInfoCollectionView; sourceTree = ""; }; + A3D1A77C29CF099400DD54EC /* ResponseDto */ = { + isa = PBXGroup; + children = ( + A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */, + ); + path = ResponseDto; + sourceTree = ""; + }; CE0C23712966D5FF00B45063 /* ViewPager */ = { isa = PBXGroup; children = ( @@ -444,6 +456,7 @@ CE10063829680C2A00FD31FB /* SignInDto */ = { isa = PBXGroup; children = ( + A3D1A77C29CF099400DD54EC /* ResponseDto */, CE10063929680C5700FD31FB /* .gitkeep */, ); path = SignInDto; @@ -857,6 +870,7 @@ CE6655AD295D7FEA00C64E12 /* Router */ = { isa = PBXGroup; children = ( + A3D1A77829CF03D200DD54EC /* AuthRouter.swift */, CE21C023299E5FE500F62AF5 /* UserRouter.swift */, CE21C025299E5FF300F62AF5 /* CourseRouter.swift */, CE21C027299E5FFC00F62AF5 /* PublicCourseRouter.swift */, @@ -1319,10 +1333,12 @@ CE18E890296C76C100FEB569 /* RNLocationModel.swift in Sources */, CE6655DC295D873500C64E12 /* UIButton+.swift in Sources */, CE21C02C299E601000F62AF5 /* ScrapRouter.swift in Sources */, + A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */, CE6655D4295D865B00C64E12 /* Publisher+UIControl.swift in Sources */, CE0D9FD329648DA300CEB5CD /* CustomAlertVC.swift in Sources */, CEB841702963360800BF8080 /* CountDownVC.swift in Sources */, CE320F38296C8FAB009F89A7 /* CourseDrawingResponseData.swift in Sources */, + A3D1A77E29CF09B600DD54EC /* SignInResponseDto.swift in Sources */, CE21C028299E5FFC00F62AF5 /* PublicCourseRouter.swift in Sources */, CE18E894296C79B900FEB569 /* CourseDrawingRequestDto.swift in Sources */, DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Global/Supports/SceneDelegate.swift b/Runnect-iOS/Runnect-iOS/Global/Supports/SceneDelegate.swift index 3080cf84..f2baba80 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Supports/SceneDelegate.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Supports/SceneDelegate.swift @@ -16,7 +16,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard let windowScene = (scene as? UIWindowScene) else { return } let window = UIWindow(windowScene: windowScene) - let nav = UINavigationController(rootViewController: SignInSocialLoginVC()) + let nav = UINavigationController(rootViewController: SplashVC()) window.rootViewController = nav self.window = window window.makeKeyAndVisible() diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift new file mode 100644 index 00000000..6de52028 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift @@ -0,0 +1,23 @@ +// +// SignInResponseDto.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/03/25. +// + +import Foundation + +// MARK: - SignInResponseDto + +struct SignInResponseDto: Codable { + let status: Int + let success: Bool + let message: String + let data: SignInResponseData +} + +// MARK: - SignInResponseData +struct SignInResponseData: Codable { + let type, email, nickname, accessToken: String + let refreshToken: String +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/SignInDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/SignInDto.swift new file mode 100644 index 00000000..cf62cc15 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/SignInDto.swift @@ -0,0 +1,14 @@ +// +// SignInDto.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/03/25. +// + +import Foundation + +// MARK: - SignInDto + +struct SignInDto: Codable { + +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift new file mode 100644 index 00000000..4dcea940 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift @@ -0,0 +1,52 @@ +// +// AuthRouter.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/03/25. +// + +import Foundation + +import Moya + +enum AuthRouter { + case getUserInfo +} + +extension AuthRouter: TargetType { + var baseURL: URL { + guard let url = URL(string: Config.baseURL) else { + fatalError("baseURL could not be configured") + } + + return url + } + + var path: String { + switch self { + case .getUserInfo: + return "api/auth" + } + } + + var method: Moya.Method { + switch self { + case .getUserInfo: + return .get + } + } + + var task: Moya.Task { + switch self { + case .getUserInfo: + return .requestPlain + } + } + + var headers: [String: String]? { + switch self { + case .getUserInfo: + return Config.headerWithDeviceId + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift index aa2ff75e..6194d2d7 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift @@ -9,6 +9,7 @@ import UIKit import SnapKit import Then +import Moya import AuthenticationServices import KakaoSDKAuth import KakaoSDKUser @@ -18,6 +19,10 @@ final class SignInSocialLoginVC: UIViewController { // MARK: - Properties + private var signInProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + let screenWidth = UIScreen.main.bounds.width // MARK: - UI Components @@ -43,16 +48,7 @@ final class SignInSocialLoginVC: UIViewController { $0.tintColor = .black } - private lazy var appleLoginButton = UIButton(type: .system).then { - $0.setTitle("Apple로 로그인", for: .normal) - $0.titleLabel?.font = .b3 - $0.setTitleColor(.white, for: .normal) - $0.setBackgroundColor(.black, for: .normal) - $0.layer.cornerRadius = 7 - $0.setImage(ImageLiterals.icApple, for: .normal) - $0.imageEdgeInsets = .init(top: 0, left: 0, bottom: 0, right: self.screenWidth * 0.5) - $0.tintColor = .white - } + private let appleLoginButton = ASAuthorizationAppleIDButton() override func viewDidLoad() { super.viewDidLoad() @@ -82,8 +78,8 @@ extension SignInSocialLoginVC { } @objc func kakaoLoginButtonDidTap(_ sender: Any) { - // isKakaoTalkLoginAvailable() : 카톡 설치 되어있으면 true - if (UserApi.isKakaoTalkLoginAvailable()) { //카톡 설치되어있으면 -> 카톡으로 로그인 + // isKakaoTalkLoginAvailable(): 카톡 설치 되어있으면 true + if (UserApi.isKakaoTalkLoginAvailable()) { // 카톡 설치되어있으면 -> 카톡으로 로그인 UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in if let error = error { print(error) @@ -188,3 +184,34 @@ extension SignInSocialLoginVC: ASAuthorizationControllerPresentationContextProvi print("Apple Login error") } } + +// MARK: - Network + +extension SignInSocialLoginVC { + func getUserInfo() { + LoadingIndicator.showLoading() + signInProvider.request(.getUserInfo) { [weak self] response in + LoadingIndicator.hideLoading() + guard let self = self else { return } + switch response { + case .success(let result): + let status = result.statusCode + if 200..<300 ~= status { + do { + let responseDto = try result.map(BaseResponse.self) + guard let data = responseDto.data else { return } + } catch { + print(error.localizedDescription) + } + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +} From 93619d6ff4e71c898bdebbf8dfbef2f69f162e99 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Sat, 25 Mar 2023 21:20:35 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Feat]=20#119=20-=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=84=9C=EB=B2=84=20=ED=86=B5?= =?UTF-8?q?=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 12 ++- .../Global/Utils/RNUtils/UserManager.swift | 99 +++++++++++++++++++ .../ResponseDto/SignInResponseDto.swift | 4 +- .../Network/Router/AuthRouter.swift | 16 +-- .../{SignInVC.swift => NickNameSetUpVC.swift} | 14 +-- .../SignIn/VC/SignInSocialLoginVC.swift | 82 +++++++-------- .../Presentation/Splash/VC/SplashVC.swift | 21 ++-- 7 files changed, 176 insertions(+), 72 deletions(-) create mode 100644 Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift rename Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/{SignInVC.swift => NickNameSetUpVC.swift} (96%) diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index d5f1b2df..4da9bef8 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ A3BC2F432966A93100198261 /* CourseDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F422966A93100198261 /* CourseDetailVC.swift */; }; A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77829CF03D200DD54EC /* AuthRouter.swift */; }; A3D1A77E29CF09B600DD54EC /* SignInResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */; }; + A3D1A78029CF142E00DD54EC /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77F29CF142E00DD54EC /* UserManager.swift */; }; A3E55BA029C815B10000D85D /* SignInSocialLoginVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3E55B9F29C815B10000D85D /* SignInSocialLoginVC.swift */; }; A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE1296D33AC001598A2 /* MyPageDto.swift */; }; A3F67AEA296E4936001598A2 /* ActivityRecordInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */; }; @@ -121,7 +122,7 @@ CEB8416E2962C45300BF8080 /* LocationSearchResultTVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEB8416D2962C45300BF8080 /* LocationSearchResultTVC.swift */; }; CEB841702963360800BF8080 /* CountDownVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEB8416F2963360800BF8080 /* CountDownVC.swift */; }; CEC2A6852961F92C00160BF7 /* CustomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A6842961F92C00160BF7 /* CustomButton.swift */; }; - CEC2A68729629B9B00160BF7 /* SignInVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68629629B9B00160BF7 /* SignInVC.swift */; }; + CEC2A68729629B9B00160BF7 /* NickNameSetUpVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68629629B9B00160BF7 /* NickNameSetUpVC.swift */; }; CEC2A68A2962ADCD00160BF7 /* RNMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A6892962ADCD00160BF7 /* RNMapView.swift */; }; CEC2A68C2962AE1B00160BF7 /* RNStartMarker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68B2962AE1B00160BF7 /* RNStartMarker.swift */; }; CEC2A68E2962AF2C00160BF7 /* RNMarker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68D2962AF2C00160BF7 /* RNMarker.swift */; }; @@ -160,6 +161,7 @@ A3BC2F422966A93100198261 /* CourseDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailVC.swift; sourceTree = ""; }; A3D1A77829CF03D200DD54EC /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = ""; }; A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInResponseDto.swift; sourceTree = ""; }; + A3D1A77F29CF142E00DD54EC /* UserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = ""; }; A3E55B9F29C815B10000D85D /* SignInSocialLoginVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInSocialLoginVC.swift; sourceTree = ""; }; A3E55BA529C8AB0A0000D85D /* Runnect-iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Runnect-iOS.entitlements"; sourceTree = ""; }; A3F67AE1296D33AC001598A2 /* MyPageDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageDto.swift; sourceTree = ""; }; @@ -272,7 +274,7 @@ CEB8416D2962C45300BF8080 /* LocationSearchResultTVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchResultTVC.swift; sourceTree = ""; }; CEB8416F2963360800BF8080 /* CountDownVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountDownVC.swift; sourceTree = ""; }; CEC2A6842961F92C00160BF7 /* CustomButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomButton.swift; sourceTree = ""; }; - CEC2A68629629B9B00160BF7 /* SignInVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInVC.swift; sourceTree = ""; }; + CEC2A68629629B9B00160BF7 /* NickNameSetUpVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NickNameSetUpVC.swift; sourceTree = ""; }; CEC2A6892962ADCD00160BF7 /* RNMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNMapView.swift; sourceTree = ""; }; CEC2A68B2962AE1B00160BF7 /* RNStartMarker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNStartMarker.swift; sourceTree = ""; }; CEC2A68D2962AF2C00160BF7 /* RNMarker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNMarker.swift; sourceTree = ""; }; @@ -771,6 +773,7 @@ CE14677729658C7200DCEA1B /* Stopwatch.swift */, CE9291282965E01D0010959C /* RNTimeFormatter.swift */, CE3A53C4296C6017003D518C /* KeychainManager.swift */, + A3D1A77F29CF142E00DD54EC /* UserManager.swift */, ); path = RNUtils; sourceTree = ""; @@ -1010,7 +1013,7 @@ CE6655C3295D837800C64E12 /* VC */ = { isa = PBXGroup; children = ( - CEC2A68629629B9B00160BF7 /* SignInVC.swift */, + CEC2A68629629B9B00160BF7 /* NickNameSetUpVC.swift */, A3E55B9F29C815B10000D85D /* SignInSocialLoginVC.swift */, ); path = VC; @@ -1269,7 +1272,7 @@ A3BC2F2F2962C40A00198261 /* UploadedCourseInfoVC.swift in Sources */, CE6655EA295D88B200C64E12 /* UITabBar+.swift in Sources */, CE9291272965D0ED0010959C /* StatsInfoView.swift in Sources */, - CEC2A68729629B9B00160BF7 /* SignInVC.swift in Sources */, + CEC2A68729629B9B00160BF7 /* NickNameSetUpVC.swift in Sources */, CE665602295D918000C64E12 /* JsonCoder.swift in Sources */, DA97A033296E65D80086760E /* CourseUploadingRequestDto.swift in Sources */, CE4545CD295D7AF4003201E1 /* TaBarController.swift in Sources */, @@ -1333,6 +1336,7 @@ CE18E890296C76C100FEB569 /* RNLocationModel.swift in Sources */, CE6655DC295D873500C64E12 /* UIButton+.swift in Sources */, CE21C02C299E601000F62AF5 /* ScrapRouter.swift in Sources */, + A3D1A78029CF142E00DD54EC /* UserManager.swift in Sources */, A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */, CE6655D4295D865B00C64E12 /* Publisher+UIControl.swift in Sources */, CE0D9FD329648DA300CEB5CD /* CustomAlertVC.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift new file mode 100644 index 00000000..304d071c --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift @@ -0,0 +1,99 @@ +// +// UserManager.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/03/25. +// + +import Foundation + +import Moya + +enum RNError: Error { + case networkFail + case etc +} + +final class UserManager { + static let shared = UserManager() + + private var signInProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + + @UserDefaultWrapper(key: "accessToken") public var accessToken + @UserDefaultWrapper(key: "refreshToken") public var refreshToken + @UserDefaultWrapper(key: "isKakao") public var isKakao + var hasAccessToken: Bool { return self.accessToken != nil } + + private init() {} + + func updateToken(accessToken: String, refreshToken: String, isKakao: Bool) { + self.accessToken = accessToken + self.refreshToken = refreshToken + self.isKakao = isKakao + } + + func signIn(token: String, provider: String, completion: @escaping(Result) -> Void) { + signInProvider.request(.signIn(token: token, provider: provider)) { [weak self] response in + guard let self = self else { return } + switch response { + case .success(let result): + let status = result.statusCode + if 200..<300 ~= status { + do { + let responseDto = try result.map(BaseResponse.self) + guard let data = responseDto.data else { return } + self.accessToken = data.data.accessToken + self.refreshToken = data.data.refreshToken + self.isKakao = provider == "KAKAO" ? true : false + completion(.success(data.data.nickname)) + } catch { + print(error.localizedDescription) + completion(.failure(.networkFail)) + } + } + if status >= 400 { + print("400 error") + completion(.failure(.networkFail)) + } + case .failure(let error): + print(error.localizedDescription) + completion(.failure(.networkFail)) + } + } + } + + func autoSignIn(completion: @escaping(Result) -> Void) { + guard let accessToken = self.accessToken else { return } + guard let isKakao = self.isKakao else { return } + let provider = isKakao ? "KAKAO" : "APPLE" + signInProvider.request(.signIn(token: accessToken, provider: provider)) { [weak self] response in + guard let self = self else { return } + switch response { + case .success(let result): + let status = result.statusCode + if 200..<300 ~= status { + do { + let responseDto = try result.map(BaseResponse.self) + guard let data = responseDto.data else { return } + self.accessToken = data.data.accessToken + self.refreshToken = data.data.refreshToken + self.isKakao = provider == "KAKAO" ? true : false + completion(.success(data.data.nickname)) + } catch { + print(error.localizedDescription) + completion(.failure(.networkFail)) + } + } + if status >= 400 { + print("400 error") + completion(.failure(.networkFail)) + } + case .failure(let error): + print(error.localizedDescription) + completion(.failure(.networkFail)) + } + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift index 6de52028..1e36747d 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/SignInDto/ResponseDto/SignInResponseDto.swift @@ -17,7 +17,9 @@ struct SignInResponseDto: Codable { } // MARK: - SignInResponseData + struct SignInResponseData: Codable { - let type, email, nickname, accessToken: String + let type, nickname, accessToken: String + let email: String? let refreshToken: String } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift index 4dcea940..e53af6d3 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift @@ -10,7 +10,7 @@ import Foundation import Moya enum AuthRouter { - case getUserInfo + case signIn(token: String, provider: String) } extension AuthRouter: TargetType { @@ -24,28 +24,28 @@ extension AuthRouter: TargetType { var path: String { switch self { - case .getUserInfo: - return "api/auth" + case .signIn: + return "/auth" } } var method: Moya.Method { switch self { - case .getUserInfo: - return .get + case .signIn: + return .post } } var task: Moya.Task { switch self { - case .getUserInfo: - return .requestPlain + case .signIn(let token, let provider): + return .requestParameters(parameters: ["token": token, "social": provider], encoding: JSONEncoding.default) } } var headers: [String: String]? { switch self { - case .getUserInfo: + case .signIn: return Config.headerWithDeviceId } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/NickNameSetUpVC.swift similarity index 96% rename from Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInVC.swift rename to Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/NickNameSetUpVC.swift index ffb4da29..4f51f24f 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/NickNameSetUpVC.swift @@ -1,5 +1,5 @@ // -// SignInVC.swift +// NickNameSetUpVC.swift // Runnect-iOS // // Created by sejin on 2023/01/02. @@ -9,7 +9,7 @@ import UIKit import Moya -final class SignInVC: UIViewController { +final class NickNameSetUpVC: UIViewController { // MARK: - Properties @@ -62,7 +62,7 @@ final class SignInVC: UIViewController { // MARK: - Methods -extension SignInVC { +extension NickNameSetUpVC { private func setDelegate() { self.nicknameTextField.delegate = self } @@ -84,7 +84,7 @@ extension SignInVC { // MARK: - @objc Function -extension SignInVC { +extension NickNameSetUpVC { @objc private func textFieldTextDidChange() { guard let text = nicknameTextField.text else { return } @@ -106,7 +106,7 @@ extension SignInVC { // MARK: - UI & Layout -extension SignInVC { +extension NickNameSetUpVC { private func setUI() { view.backgroundColor = .w1 } @@ -140,7 +140,7 @@ extension SignInVC { // MARK: - UITextFieldDelegate -extension SignInVC: UITextFieldDelegate { +extension NickNameSetUpVC: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() return true @@ -149,7 +149,7 @@ extension SignInVC: UITextFieldDelegate { // MARK: - Network -extension SignInVC { +extension NickNameSetUpVC { func signIn(nickname: String) { LoadingIndicator.showLoading() userProvider.request(.signUp(nickname: nickname)) { [weak self] response in diff --git a/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift index 6194d2d7..aa0afcc4 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/SignIn/VC/SignInSocialLoginVC.swift @@ -19,10 +19,6 @@ final class SignInSocialLoginVC: UIViewController { // MARK: - Properties - private var signInProvider = MoyaProvider( - plugins: [NetworkLoggerPlugin(verbose: true)] - ) - let screenWidth = UIScreen.main.bounds.width // MARK: - UI Components @@ -85,23 +81,37 @@ extension SignInSocialLoginVC { print(error) } else { print("카카오 톡으로 로그인 성공") - - _ = oauthToken - /// 로그인 관련 메소드 추가 - + guard let oauthToken = oauthToken else { return } + UserManager.shared.signIn(token: oauthToken.accessToken, provider: "KAKAO") { [weak self] result in + switch result { + case .success(let nickname): + print(nickname) + self?.pushToNickNameSetUpVC() + case .failure(let error): + print(error) + self?.showNetworkFailureToast() + } + } } } } else { - // 카톡 없으면 -> 계정으로 로그인 UserApi.shared.loginWithKakaoAccount { (oauthToken, error) in if let error = error { print(error) } else { print("카카오 계정으로 로그인 성공") - - _ = oauthToken - // 관련 메소드 추가 + guard let oauthToken = oauthToken else { return } + UserManager.shared.signIn(token: oauthToken.accessToken, provider: "KAKAO") { [weak self] result in + switch result { + case .success(let nickname): + print(nickname) + self?.pushToNickNameSetUpVC() + case .failure(let error): + print(error) + self?.showNetworkFailureToast() + } + } } } } @@ -115,6 +125,11 @@ extension SignInSocialLoginVC { self.appleLoginButton.addTarget(self, action: #selector(touchUpAppleLoginButton), for: .touchUpInside) self.kakaoLoginButton.addTarget(self, action: #selector(kakaoLoginButtonDidTap), for: .touchUpInside) } + + private func pushToNickNameSetUpVC() { + let nicknameSetUpVC = NickNameSetUpVC() + self.navigationController?.pushViewController(nicknameSetUpVC, animated: true) + } } // MARK: - UI & Layout @@ -169,11 +184,21 @@ extension SignInSocialLoginVC: ASAuthorizationControllerPresentationContextProvi /// 계정 정보 가져오기 let userIdentifier = appleIDCredential.user let idToken = appleIDCredential.identityToken! - let tokeStr = String(data: idToken, encoding: .utf8) + guard let tokeStr = String(data: idToken, encoding: .utf8) else { return } print("User ID : \(userIdentifier)") print("token : \(String(describing: tokeStr))") + UserManager.shared.signIn(token: tokeStr, provider: "APPLE") { [weak self] result in + switch result { + case .success(let nickname): + print(nickname) + self?.pushToNickNameSetUpVC() + case .failure(let error): + print(error) + self?.showNetworkFailureToast() + } + } default: break } @@ -184,34 +209,3 @@ extension SignInSocialLoginVC: ASAuthorizationControllerPresentationContextProvi print("Apple Login error") } } - -// MARK: - Network - -extension SignInSocialLoginVC { - func getUserInfo() { - LoadingIndicator.showLoading() - signInProvider.request(.getUserInfo) { [weak self] response in - LoadingIndicator.hideLoading() - guard let self = self else { return } - switch response { - case .success(let result): - let status = result.statusCode - if 200..<300 ~= status { - do { - let responseDto = try result.map(BaseResponse.self) - guard let data = responseDto.data else { return } - } catch { - print(error.localizedDescription) - } - } - if status >= 400 { - print("400 error") - self.showNetworkFailureToast() - } - case .failure(let error): - print(error.localizedDescription) - self.showNetworkFailureToast() - } - } - } -} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift index 3230a3b1..9b6c2cd6 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/Splash/VC/SplashVC.swift @@ -40,20 +40,25 @@ final class SplashVC: UIViewController { extension SplashVC { private func checkDidSignIn() { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - let deviceId = KeychainManager.shared.getDeviceId() - if deviceId.isEmpty { - let deviceIdStoreSuccess = KeychainManager.shared.storeDeviceId() - guard deviceIdStoreSuccess else { return } + if UserManager.shared.hasAccessToken { + UserManager.shared.autoSignIn { [weak self] result in + switch result { + case .success(let nickname): + print(nickname) + self?.pushToTabBarController() + case .failure(let error): + print(error) + self?.pushToSignInView() + } + } + } else { self.pushToSignInView() - return } - - self.pushToTabBarController() } } private func pushToSignInView() { - let signInVC = SignInVC() + let signInVC = SignInSocialLoginVC() self.navigationController?.pushViewController(signInVC, animated: true) } From fc6911727eb90d9cfed3e27ecb20046be444cdf5 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Sat, 25 Mar 2023 21:24:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Feat]=20#119=20-=20headerWithAccessToken?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift | 2 +- Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift | 2 +- Runnect-iOS/Runnect-iOS/Network/Router/PublicCourseRouter.swift | 2 +- Runnect-iOS/Runnect-iOS/Network/Router/RecordRouter.swift | 2 +- Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift | 2 +- Runnect-iOS/Runnect-iOS/Network/Router/StampRouter.swift | 2 +- Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift index e53af6d3..e6f3ad40 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/AuthRouter.swift @@ -46,7 +46,7 @@ extension AuthRouter: TargetType { var headers: [String: String]? { switch self { case .signIn: - return Config.headerWithDeviceId + return Config.headerWithAccessToken } } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift index 16712503..2c779635 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/CourseRouter.swift @@ -92,7 +92,7 @@ extension CourseRouter: TargetType { return ["Content-Type": "multipart/form-data", "machineId": Config.deviceId] default: - return Config.headerWithDeviceId + return Config.headerWithAccessToken } } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/PublicCourseRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/PublicCourseRouter.swift index 6e70575d..2bfa41df 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/PublicCourseRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/PublicCourseRouter.swift @@ -59,7 +59,7 @@ extension PublicCourseRouter: TargetType { var headers: [String: String]? { switch self { default: - return Config.headerWithDeviceId + return Config.headerWithAccessToken } } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/RecordRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/RecordRouter.swift index a5388fa7..3f896268 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/RecordRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/RecordRouter.swift @@ -57,7 +57,7 @@ extension RecordRouter: TargetType { var headers: [String: String]? { switch self { case .recordRunning, .getActivityRecordInfo: - return Config.headerWithDeviceId + return Config.headerWithAccessToken } } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift index f3e30cc4..fc23a636 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/ScrapRouter.swift @@ -53,7 +53,7 @@ extension ScrapRouter: TargetType { var headers: [String: String]? { switch self { case .createAndDeleteScrap, .getScrapCourse: - return Config.headerWithDeviceId + return Config.headerWithAccessToken } } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/StampRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/StampRouter.swift index f4cbdf30..36b09646 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/StampRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/StampRouter.swift @@ -46,7 +46,7 @@ extension StampRouter: TargetType { var headers: [String: String]? { switch self { case .getGoalRewardInfo: - return Config.headerWithDeviceId + return Config.headerWithAccessToken } } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift index 3d330af3..c820973d 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift @@ -54,6 +54,6 @@ extension UserRouter: TargetType { } var headers: [String: String]? { - return Config.headerWithDeviceId + return Config.headerWithAccessToken } }