#Handling a homepage with two very different flavours depending on whether you're logged in or not

1 messages · Page 1 of 1 (latest)

celest quest
#

I'm building a web app where the home for logged in users will be very feature rich (a dashboard) but the non-logged in version is very basic (not much more than some copy and a log in form)

I've started implementing this as a single view with a chunky 'if' in it. If you're not logged, you get public_homepage.html. If you are logged in then I load all kinds of stuff and you get dashboard.html. You're always at / though.

I'm getting a nagging feeling that this is a bit hacky, and these things might deserve their own routes and views, but I'm not sure what this is based on. I guess I'd protect the /dashboard route, like most of the others, and send people back to the public home on /, and once you log in you get directed (by default) to /dashboard

What do you tend to do here? What are the patterns and factors you think about?

barren nymph
#

Only use If is simple and work

mild spoke
#

Agreed. If it works (without breaking anything), then you're good

clear kraken
#

I'd check if the user is logged in and then either serve a different template or redirect them to another view. A giant chunky if is OK, of course, but there are cleaner solutions

celest quest
opal blade
#

Could be either. You can redirect (tell to go to different url) or just conditionally pass request to another view

clear kraken