Skip to content

Commit

Permalink
로그아웃하고 앱을 다시 실행시켜서 사용자가 로그인했을 때 FeedVC 가 present되지 않는 버그를 발견했는데 못 고쳤다…
Browse files Browse the repository at this point in the history
….. (브랜치 쓸걸) 다시 이전 커밋 state로 돌아가기 위한 커밋..
  • Loading branch information
SHcommit committed Nov 2, 2022
1 parent ed610f6 commit c08f133
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 18 deletions.
Expand Up @@ -16,5 +16,21 @@
categories = "Hang Risk">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "1E21884A-E5BE-4604-A40D-5C3E227AEBC3"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Instagram/Controller/Authentication/LoginController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "215"
endingLineNumber = "215"
landmarkName = "didTapLoginButton(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
3 changes: 1 addition & 2 deletions Clone App/Instagram/Instagram/API/AuthService.swift
Expand Up @@ -19,9 +19,8 @@ struct AuthService {

ImageUploader.uploadImage(image: image) { imageUrl in
AUTH.createUser(withEmail: info.email.value, password: info.password.value) { result, error in
guard error == nil else { print("Fail uploadImage"); return }
guard error == nil else { print("Fail uploadImage: \(error?.localizedDescription)"); return }
guard let uid = result?.user.uid else { return }

let userModel = info.getUserInfoModel(uid: uid, url: imageUrl)
let encodedUserModel = encodeToNSDictionary(codableType: userModel)
COLLECTION_USERS.document(uid).setData(encodedUserModel, completion: completion)
Expand Down
1 change: 0 additions & 1 deletion Clone App/Instagram/Instagram/API/ImageUploader.swift
Expand Up @@ -19,7 +19,6 @@ struct ImageUploader {
print("DEBUG : Failed to upload image \(error.localizedDescription)")
return
}

ref.downloadURL { url, error in
guard let imageUrl = url?.absoluteString else { return }
completion(imageUrl)
Expand Down
Expand Up @@ -211,7 +211,13 @@ extension LoginController {
return
}
guard let vc = self.presentingViewController as? MainHomeTabController else {
print("no")

print("DEBUG: No")
let vc = MainHomeTabController()
vc.modalPresentationStyle = .fullScreen
vc.fetchUserInfo()
present(vc, animated: false)

return
}
endIndicator(indicator: indicator)
Expand Down
Expand Up @@ -220,12 +220,11 @@ extension RegistrationController {
@objc func didTapSignUpButton(_ sender: Any) {
startIndicator(indicator: indicator)
AuthService.registerUser(withUserInfo: vm) { [self] error in

if let error = error {
endIndicator(indicator: indicator)
print("DEBUG : Failed register user info in Firestore Database \(error.localizedDescription)")
return
}

print("DEBUG : Successful registered user with fireStore")
endIndicator(indicator: indicator)
self.navigationController?.popViewController(animated: true)
Expand Down
2 changes: 2 additions & 0 deletions Clone App/Instagram/Instagram/Controller/FeedController.swift
Expand Up @@ -89,7 +89,9 @@ extension FeedController {
extension FeedController {
@objc func handleLogout() {
do {
print("Logout user: \(Auth.auth().currentUser?.email)")
try Auth.auth().signOut()
print("Check really logouted user: \(Auth.auth().currentUser?.email)")
DispatchQueue.main.async {
self.presentLoginScene()
}
Expand Down
Expand Up @@ -22,6 +22,11 @@ class MainHomeTabController: UITabBarController {
super.viewDidLoad()
view.backgroundColor = .white
configure()

}

override func viewWillAppear(_ animated: Bool) {
configure()
}

}
Expand All @@ -31,8 +36,8 @@ extension MainHomeTabController {

func configure() {
customTabBarUI()
checkIfUserIsLoggedIn()
fetchUserInfo()
checkIfUserIsLoggedIn()
}

func configureViewControllers() {
Expand All @@ -57,6 +62,7 @@ extension MainHomeTabController {
viewControllers = [feed,search,imageSelector,notifications,profile]
}


}

//MARK: - Setup NavigationController Helpers
Expand Down Expand Up @@ -113,13 +119,13 @@ extension MainHomeTabController {
}
}



//MARK: - API. check user's membership
func checkIfUserIsLoggedIn() {
if Auth.auth().currentUser == nil {
DispatchQueue.main.async {
self.view.isHidden = true
self.presentLoginScene()
}
if CURRENT_USER == nil {
self.view.isHidden = true
self.presentLoginScene()
}
}

Expand All @@ -131,15 +137,13 @@ extension MainHomeTabController {
self.present(nav,animated: false, completion: nil)
}


}

//MARK: - Implement AuthentificationDelegate
extension MainHomeTabController: AuthentificationDelegate {
func authenticationCompletion() {
UserService.fetchCurrentUserInfo() { userInfo in
guard let userInfo = userInfo else { return }
self.userVM = UserInfoViewModel(user: userInfo, profileImage: nil)
}
fetchUserInfo()
self.dismiss(animated: false)
}

Expand Down
2 changes: 1 addition & 1 deletion Clone App/Instagram/Instagram/SceneDelegate.swift
Expand Up @@ -17,8 +17,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)

window?.rootViewController = MainHomeTabController()

//window?.rootViewController = UINavigationController(rootViewController: LoginController())
window?.makeKeyAndVisible()

Expand Down
3 changes: 2 additions & 1 deletion Clone App/Instagram/Instagram/Utils/Extensions.swift
Expand Up @@ -26,6 +26,7 @@ extension UIViewController {

DispatchQueue.main.async {
self.view.bringSubviewToFront(indicator)
indicator.isHidden = false
indicator.startAnimating()
}
}
Expand All @@ -39,7 +40,7 @@ extension UIViewController {

func setupIndicatorConstraints(indicator: UIActivityIndicatorView) {
view.addSubview(indicator)
indicator.hidesWhenStopped = true
indicator.hidesWhenStopped = true
indicator.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([indicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
indicator.centerYAnchor.constraint(equalTo: view.centerYAnchor)])
Expand Down
Expand Up @@ -23,6 +23,7 @@ struct UserInfoViewModel {

extension UserInfoViewModel {

//MARK: - Get user value
func getUserName() -> String {
return user.username
}
Expand All @@ -39,7 +40,15 @@ extension UserInfoViewModel {
return user
}

func getUserEmail() -> String {
return user.email
}

//MARK: - Set user value

func setUserProfile(iv: UIImageView) {
iv.image = profileImage
}


}

0 comments on commit c08f133

Please sign in to comment.