Skip to content

Commit

Permalink
Merge pull request #285 from OMZigak/feat-#284-reissueMade
Browse files Browse the repository at this point in the history
[feat] 마스터 엑세스토큰 주입
  • Loading branch information
hooni0918 authored Aug 8, 2024
2 parents 3af00cd + bd35b10 commit dbd2ea0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
1 change: 0 additions & 1 deletion KkuMulKum/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} else {
print("Failed to load KAKAO_APP_KEY from PrivacyInfo.plist")
}

setupFirebase(application: application)

return true
Expand Down
4 changes: 1 addition & 3 deletions KkuMulKum/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
loginViewModel.autoLogin { [weak self] success in
DispatchQueue.main.async {
if success {
print("Auto login successful, showing main screen")
self?.showLoginScreen()
self?.showMainScreen()
} else {
print("Auto login failed, showing login screen")
self?.showLoginScreen()
}
}
Expand Down
27 changes: 26 additions & 1 deletion KkuMulKum/Source/Onboarding/Login/VIewModel/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class LoginViewModel: NSObject {
}

private func saveTokens(accessToken: String, refreshToken: String) {
print("Attempting to save tokens")

let accessTokenSaved = authService.saveAccessToken(accessToken)
let refreshTokenSaved = authService.saveRefreshToken(refreshToken)

Expand All @@ -259,6 +259,31 @@ class LoginViewModel: NSObject {
print("Failed to save tokens")
}
}

// TODO: 자동로그인 구현 후 삭제예정
func fetchValueFromPrivacyInfo(forKey key: String) -> String? {
guard let path = Bundle.main.path(forResource: "PrivacyInfo", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
let value = dict[key] as? String else {
return nil
}
return value
}

// TODO: 자동로그인 구현 후 삭제예정
func performTestLogin() {
guard let testAccessToken = fetchValueFromPrivacyInfo(forKey: "TEST_ACCESS_TOKEN") else {
print("Failed to retrieve test access token")
error.value = "Test access token not found"
return
}

saveTokens(accessToken: testAccessToken, refreshToken: "")
userName.value = ""
loginState.value = .login
}


}

extension LoginViewModel: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
Expand Down
19 changes: 17 additions & 2 deletions KkuMulKum/Source/Onboarding/Login/View/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ class LoginView: BaseView {
$0.isUserInteractionEnabled = true
}

// TODO: 자동로그인 구현 후 삭제예정
let testLoginButton = UIButton().then {
$0.setTitle("Test Login", for: .normal)
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .systemBlue
$0.layer.cornerRadius = 10
}

override func setupView() {
addSubviews(backgroundImageView, appleLoginImageView, kakaoLoginImageView)
addSubviews(backgroundImageView, appleLoginImageView, kakaoLoginImageView, testLoginButton)
}

override func setupAutoLayout() {
Expand All @@ -51,6 +59,13 @@ class LoginView: BaseView {
$0.horizontalEdges.equalToSuperview().inset(14)
$0.height.equalTo(Screen.height(54))
}


// TODO: 자동로그인 구현 후 삭제예정
testLoginButton.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(appleLoginImageView.snp.bottom).offset(20)
$0.width.equalTo(200)
$0.height.equalTo(50)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class LoginViewController: BaseViewController {
action: #selector(kakaoLoginTapped)
)
loginView.kakaoLoginImageView.addGestureRecognizer(kakaoTapGesture)

// TODO: 자동로그인 구현 후 삭제예정
loginView.testLoginButton.addTarget(self, action: #selector(testLoginTapped), for: .touchUpInside)

}

private func bindViewModel() {
Expand All @@ -55,7 +59,7 @@ class LoginViewController: BaseViewController {
print("Login State: Not logged in")
case .login:
print("Login State: Logged in")
await owner.navigateToMainScreen()
await owner.navigateToMainScreen()
case .needOnboarding:
print("Login State: Need onboarding")
await owner.navigateToOnboardingScreen()
Expand All @@ -66,7 +70,7 @@ class LoginViewController: BaseViewController {
loginViewModel.userName.bind(with: self) { owner, name in
Task {
if name != nil {
await owner.navigateToOnboardingScreen()
await owner.navigateToMainScreen()
} else {
await owner.navigateToOnboardingScreen()
}
Expand Down Expand Up @@ -129,4 +133,8 @@ class LoginViewController: BaseViewController {
present(alert, animated: true)
}
}

@objc private func testLoginTapped() {
loginViewModel.performTestLogin()
}
}

0 comments on commit dbd2ea0

Please sign in to comment.