Apologies
You must be signed in to watch this lesson.
Login / Logout Delegation
Tinder Firestore Swipe and Match
In today's lesson, we'll cover the aspect of logging out of our application by tapping the Log Out button in our Settings page. Upon logging out, we'll first make a call to Firebase Auth and sign out of our application. Next we'll discuss another step in our app where we can setup custom delegation again to signal that our user has logged back in. This might be a little hard to follow if you're not used to setting up these delegation links, so make sure to leave any question down below.

Comments (17)
st4n
5 years ago
hey, unfortunately thumbs down for copy-paste from me :( The whole idea of learning it's through the repetition. fixes needed: 1. when logging out "Go back" button does not work (there is nothing to pop), restarting the app gets you again into the login screen without possibility of registration new user. Maybe some check in AppDelegate is needed? 2. I'm encountering a bug with PageControl in user cards (3 the same photos for some users) - please check in your version
Brian Voong
5 years ago
st4n
5 years ago
I wouldn't mind, like at all, if it was only the UI code (I have snippets prepared for all this UI closures to speed things up). This MVVM stuff is just fairly new to me, and I know I got to repeat this a few times to get used to the concept. Especially this binder / observer stuff. 1. will check it out and apply :) 2. I have to check my past commits, to find when this problem started to occurr. I'll let you know. ps. please don't mind my complaining too much sometimes. :) I'm super happy with this course. Add the way it's evolving..super cool.
st4n
5 years ago
hey, two things: 1. i checked - the problem started to occur after episode 28. 2. your downloadable project (from this page) is also terribly bugged when it comes to viewing user photos within the card.
st4n
5 years ago
got it, I guess.. the problem is when we are saving settings, we are saving also imageUrl2, imageUrl2 as an empty string that causes loading "empty" images later and populating 2 extra pageControll bars. The funny blink effect can be achieved whe registering user with no photo, and the add photo as the 2nd or 3rd :) another problem: when registering the user, default age seek parameters are -1, so after login the app can't fetch users and the hud is blocking user interactions. my humble sugestion: plz do (later) the whole episode of fixing bugs (not only upload code - it is so hard to track every subtle change in the codebase + some bugfixes can be really nice exercise).
Brian Voong
5 years ago
azhar
5 years ago
Agree with st4n, the UI code being copy pasted is manageable but the view model concept is new to most of. Copying the view model class over does do harm.
Daryl Wong
5 years ago
Hi Brian, could you put the 2 files here so that we could download them? The two files in the download project already has the delegate added.
Brian Voong
5 years ago
Alfrad
5 years ago
Hi Brian, At around 14:38 I realised the textfield is missing "tf.backgroundColor = .white", but your simulator is still able to display the white background. May I check with you why is that so because I got the gradient layer background instead? Thank you.
diegogarciar
5 years ago
I believe he's now setting that property inside the CustomTextfield
Shaq Noir
5 years ago
The HomeController goes into permanent 'loading' hud display after importing the downloadable Login Controller / View Model Files you provided.
Shaq Noir
5 years ago
Okay, I've double-checked and the issue actually occurs when I type 'self.dismiss(animated:true)' on line 71 in LoginController - the problem disappears when I remove that line - any ideas ?
Michalis
5 years ago
Hi Brian, In some previous projects I was using singleton pattern to setup Firebase authentication and its helper functions like queries. Those were MVC projects. I see you are not using singleton. Are there any cons when switching to MVVM? Except for traditional controversy over singleton ;-) Michal
richardbranson
5 years ago
hi brian some problem when i register a new user and then run the app when I left or right swipe card and tap to the card to show if more card is available then tap to last card error show index out of bound in the card view model(image index = 0) and cards can misbehave like other image show in other cards above below
Dongjun Kim
5 years ago
Hi Brian! delegate in RegistrationController works well, but delegate in LoginController couldn't call didFinishLoggingIn() in HomeController. I think when we check currentUser in viewDidAppear of HomeController if currentUser is nil, registrationController is presented and registration's delegate is self(HomeController) but LoginController can't delegate HomeController So permanent loading HUD happens after I logged in
Brian Voong
5 years ago
Julia Pak
4 years ago
I've got the same :(
alokach123
4 years ago
try dismissing the jgprogress hud in fetch users
ndevereaux
4 years ago
Hey Brian, you mentioned that there was a reason for creating a navController with the LoginController when presenting the LoginController. Can you explain why you did this rather than just presenting the LoginController without the navController?
Brian Voong
4 years ago
ndevereaux
4 years ago
Oh because we changed it from "present" to "push". Cool thanks!
rehannali
4 years ago
Hi Brain! I saw your logic for login/registration and home controller. My question is, Isn't we have to assign home controller after login and registration after logout to rootViewController of application? Isn't this best practice for writing these login/logout?
Eugeneberezin
4 years ago
I've noticed a very interesting behavior. When I run my app on a real device I get an error in code for Firebase code "no identifiers found" os similar. The code compiles and I am able to run the application but if my real device is connected to my Xcode then I get that weird error that would go away during building the code.
David Guarino
4 years ago
Hey Brian, Everything was going smooth until about the 13 minute mark when the files got added. I personally like your style of teaching but being a novice in writing programmatic UI components, Bindable, and MVVM my attention span was lost. I know it's almost the same as earlier lessons but in order for us to fully grasp the concept we need to see it again until we become competent in what you're teaching us. This was just a little bump in the road but I'll try to keep.....Thanks for your YouTube videos, courses, and most importantly your time!
Dino32
4 years ago
Hi Brian, Please tell me, why do you use "cardsDeckView.subviews.forEach({$0.removeFromSuperview()})" in fetchCurrentUser(). Was it just in case if some cards are still upon view after previous logged in user ?
Brian Voong
4 years ago
majdjamaleddine@gmail.com
4 years ago
Hi Brian, what is the difference between 'push' and 'present'? Thanks
Brian Voong
4 years ago
Kevin Liu
4 years ago
Seems to be a bug with iOS 13. When we click logout, the viewDidAppear() in the HomeController is not being called.
Kevin Liu
4 years ago
So we're not showing the registration page when we click logout. Do you have a fix for this Brian?
harryalexander
4 years ago
Hi there - I had the same issue! I fixed it by adding the line navController.modalPresentationstyle = .fullScreen to the handleSettings function as below: @objc func handleSettings() { let settingsController = SettingsController() settingsController.delegate = self let navController = UINavigationController(rootViewController: settingsController) navController.modalPresentationStyle = .fullScreen present(navController, animated: true) } Also makes the controller full screen which was annoying me for a while! Think it is worth adding when the registrationController is presented too.
joker45
4 years ago
Yes it was a little bump, the copy & paste, but i guess it was a very good challenge to proof the own knowledge and get it deeper by trying to write this code for loginController & loginViewModel by self. For me it works fine. So i was able to fix some bugs by self directly (changed the registrationcontroller & logincontroller) - but some bugs still happen, like if you logged in, cards loaded, logged out, again logged in, than you have duplicate cards, because the the cardViewModels not reseted. Nothing that can't be fixed by self. It's again a good challenge to dive deeper in code and try to think by self and not only writing from brian videos like a zombie :)
Brian Voong
4 years ago
alokach123
4 years ago
Hey Brian, I looked over your code and I can't seem to figure out this bug that has been occuring. I did if auth.auth.currentuser == nil{ let regControler = RegistrationController() registrationController.delegate = self let navController = UInavcontroller(rootviewcontroller: regController) navController.modalPresentationStyle = .fullscreen present(navcontroller, animated: true, completion: nil) } I have set everything according to what you have however, it gets stuck on the progress hud and on the homeviewcontroller. I have not even logged out yet
alokach123
4 years ago
Never mind, I found the problem. Hey Brian, if you could update the code for HomeController.swift. under fetch current user the JGProgresshud does not get dismissed after the call for fetchingUsers completes. That was the one bug that kept me stuck on a JGProgressHud screen.
HELP & SUPPORT