How to redirect to item in webshop after successful oAuth login

When a user selects an item and is not logged in, then s*he is requested to login to order it. The users expect to be redirected to last item visited and not start over again to search for the item.

We let users sign up with oAuth / fairlogin, so the relevant code is in : apps/frappe/frappe/utils/

def redirect_post_login(desk_user):
        # redirect!
        frappe.local.response["type"] = "redirect"

        # the #desktop is added to prevent a facebook redirect bug
#       frappe.local.response["location"] = "/desk#desktop" if desk_user else "/me"
# after login go to start page, not to settings RAS 2019-09-28
        frappe.local.response["location"] = "/desk#desktop" if desk_user else "/"

I can change the location after the else, however I also do not want the user show the start page. Is there any such command like frappe.local.response["location"] = history -1 so that users see again the page before they had logged in?

The solution is to set the redirect-to to use the referrer in like this

def get_context(context):
	redirect_to = frappe.local.request.args.get("redirect-to")
	if not redirect_to:
		redirect_to = frappe.local.request.referrer

I want to submit a PR but it’s hard to explain it well enough to get the PR approved.

I submitted a PR to fix this