How to redirect a user to custom page after they logged in?

Is there a way to do this or with same effect?


I think you should set the home page path in the role and assign that role to the user. It might work, but I’m not sure. Please try this.

@auliabismar

Auth Hooks in Frappe allows you to execute custom logic during user authentication, providing flexibility in handling role-based redirects and other authentication-related tasks.

Enabling auth_hooks

  1. In your app’s hooks.py file, add the auth_hooks line to specify the method to be executed during authentication.
# apps/your_app/your_app/hooks.py
auth_hooks = ["your_app.file_name.method_name"]
  1. Create a Python file (if it doesn’t already exist) and define the method specified in auth_hooks. Below is an example of how to implement custom logic based on user roles.
# apps/your_app/your_app/file_name.py
def method_name():
    rolename = frappe.get_roles(frappe.session.user)    
    # Custom logic based on your requirements
    if rolename[0] == "specific_role":
        member = frappe.db.get_list('Doctype')
        frappe.local.response["home_page"] = "/page_name/" + member[0].name

or

user = frappe.session.user
roles = frappe.get_roles(user)
if "*****" in roles:
      frappe.local.response["home_page"] = "/my_new_page"

The frappe.get_roles(frappe.session.user) function retrieves the roles of the currently logged-in user.

1 Like

This work for me

tried that before, and it doesn’t work

will try this solution this week and will let you know!