[SOLVED] How to close all content on logout

I have an app with a logout link in the menu bar. When it’s clicked, I’d like the entire content of the app to disappear and then call anvil.users.login_with_form()

I can clear the content panel, but the menu and navbars are still visible behind the login form. Is there a way I can clear those and make it look exactly the same as when the app is first visited?

1 Like

Could you not first log the user out, then just do an open_form() on the main form that would be the opening landing page?

That should replace everything else with the landing page.

I wasn’t too sure about calling open_form on the main form from within the main form itself!!

having tried it, there’s no problem but it still leaves the menu and navbar visible.

Oh - how are you displaying the menu & navbar?

EDIT - ah, is this the Anvil admin card panel form, with the sidebar?

yep. that’s exactly it

Right, I further assume you are then dynamically updating those with menu options and the like at runtime? Reloading the page should show what was present at design time unless you add things at runtime.

nope - no dymanic content (yet)

OK, I’m not sure I understand.

What content is showing when you log off and redisplay that page that is not showing when you first hit the landing page (ie a new visitor)?

Any chance of screenshots?

Demo app: https://TVUBQIT2ZMBLOSEM.anvilapp.net/LNDJC5TTMJ7PJPZMBLQGLJHE

When you first visit, you see nothing but the login form. If you logout, you see the login form with the menu and navbar behind it.

Clone link for that: https://anvil.works/ide#clone:TVUBQIT2ZMBLOSEM=X7GX3INIHDXIPZFZ42W62ZRQ

I could open a completely different ‘Goodbye’ form that has a ‘login again’ button, I suppose

I was thinking have a Login form that shows the popup.
Then in your main form init, open that form if the user is not logged in.
Then in your logout method, open the login form.

Something like that.

Your initial blank page relies on the fact the form underneath has not been shown yet.

Yep, I think something along those lines of either a login form or a ‘goodbye’ form or some combination of both is the way forward here.

thanks for the help!

1 Like

NP.

If you take that approach, make sure to do the login code on the login form in the “show” event, not under init else the Main form will still be visible. Example :

https://anvil.works/ide#clone:ZKGLGKYA2R25XSK6=OWIYRIQAEBVQXGSEYDLQPMTJ

6 Likes

yep. already hit that one and corrected it!

Not sure if you have solved it, but for others reading this post another way is this:

def logout_lnk_click():
anvil.users.logout()
self.parent.parent.clear()
open_form(’start_page’)

Note: I have added navigation items as a component on each form and have a logout link within that component. On the start page I have the login form on start up if the user is not logged in.

2 Likes

2 posts were split to a new topic: Removing all content on logout