0

I am creating a web application in which there is a page (let's call it 'event' page) which is not login protected(i.e. users can see the page without logging in). The page shows some event details to which user can select if they are attending or not by clicking appropriate button.

Upon clicking the button, user is redirected to login page since they need to login before they can choose an option.

Once the user is goes to login page, I want to redirect the user back to the 'event' page after they login. How do I do that?

If the 'event' page was login protected, I know I can use Flask 'next' to redirect user to the page they were trying to view which needs login. But how do I implement this for pages that are not login protected?

Ankit Sahay
  • 1,710
  • 8
  • 14

1 Answers1

1

Surprisingly, I used the "session" object in Flask to solve the problem. I was under the impression that "session" comes into play only after user has logged in, but apparently not.

When user clicked to register their response, before redirecting them to sigin page I stored the current url in the session storage like:

session['prev_url'] = request.url 

Then on the signin page, after successful signin, I checked the 'prev_url' key in session, if it exists, I redirected to that page else I redirected to home page. Something like:

if session.get('prev_url') is not None:
    return redirect(session.get('prev_url'))
return redirect(url_for('index'))
Ankit Sahay
  • 1,710
  • 8
  • 14