frappe

Custom middleware to redirect user based on a role based on certain checks


I am trying to customize my frappe app based on a role.

  1. user with Role Website logs in.
  2. Check if the user has company set
  3. If it is not set then redirect them to a custom page where they can select company.

If the user tries to navigate away to any other URL then redirect them to Step 2. I believe it can be done with a middleware. But, my question is, where would we invoke the middleware in my custom app?

I tried to to add a custom middleware and tried to invoke in the frappe app but I dont think this is the suggested way.


Solution

  • You should be able to add an auth or login hook to do this for you. Check the user data, set the route location in the flags and raise frappe.Redirect

    Refs: