Anvil: Web apps with nothing but Python Transcripts
Chapter: User management and authentication
Lecture: Logging out

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw we can register
0:02 and we saw we can drive the user interface
0:04 based on whether or not there is a user
0:06 even from remembering us from session to session, right?
0:09 So if I run this now
0:11 we'll see that account and logout are shown
0:13 but that login and register are not.
0:16 However, we probably want to let them log out
0:19 at some point, right?
0:20 So let's go do that, that turns out to be super, super easy.
0:23 So when you go down here and you click this
0:25 you see Anvil.users.logout.
0:31 Not too hard, huh?
0:32 And we also want to go back home and set this user state.
0:38 Okay, so we're going to go do those three things.
0:41 I'm going to log out
0:42 and then we want to set this to be None
0:45 because we've logged them out
0:47 and then we're going to go home
0:48 that's going to trigger a refresh
0:50 of potentially that home screen
0:52 and show the anonymous view.
0:54 if you're on the home screen, of course
0:55 it's just going to toggle that
0:56 but if you were maybe somewhere else
0:57 like in your account page
0:58 got to take 'em somewhere that's valid
1:00 and home is always valid.
1:02 Let's run that.
1:03 All right, we're logged in, as you can see right here.
1:06 I click logout, it should change this menu.
1:09 Should re-navigate us home
1:10 which is going to reload this to home anonymous view.
1:13 Let's give it a shot, here we go. Again, the cell.
1:18 All right, let's try it one more time.
1:20 Well, our logout worked.
1:21 We just weren't able to update.