Redirect upon logging in based on user role in 6.0.0 #38580
-
|
Hi, I recently upgraded from 4.1.1 to 6.0.0 and found that my previous customization no longer works. In 4.1.1, I had modified SupersetIndexView(IndexView) in initialization/init.py so that, after logging in, users were redirected to a different URL depending on their role. In other words, instead of always sending users to /superset/welcome/, I was routing each type of user to a specific dashboard or page after authentication. After upgrading to 6.0.0, that customization no longer seems to apply. What is the recommended way to achieve this in v6? I could not find any documentation or examples about role-based post-login redirects. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
Your previous approach no longer works because Superset v6 migrated to a React frontend that decoupled UI routing from Flask/FAB backend logic. The Recommended Solution: Use a custom security manager to implement role-based redirects: # In your superset_config.py
from flask_appbuilder.security.views import AuthView
from flask import redirect, g
from superset.security import SupersetSecurityManager
class CustomAuthView(AuthView):
@expose("/")
def index(self):
if g.user and g.user.is_authenticated:
# Custom role-based redirect logic
if 'Admin' in [role.name for role in g.user.roles]:
return redirect('/superset/dashboard/list/')
elif 'Alpha' in [role.name for role in g.user.roles]:
return redirect('/chart/list/')
else:
return redirect('/superset/welcome/')
return super().index()
class CustomSecurityManager(SupersetSecurityManager):
authview = CustomAuthView
CUSTOM_SECURITY_MANAGER = CustomSecurityManagerThis approach is confirmed to work in v6. You can adapt the role checks and redirect URLs to match your requirements. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
@dosu I edited the post to better explain what I'm looking for with this discussion. In 4.1.1, I had modified SupersetIndexView(IndexView) in initialization/init.py so that, after logging in, users were redirected to a different URL depending on their role. In other words, instead of always sending users to /superset/welcome/, I was routing each type of user to a specific dashboard or page after authentication. After upgrading to 6.0.0, that customization no longer seems to apply. What is the recommended way to achieve this in v6? |
Beta Was this translation helpful? Give feedback.
-
|
For anybody interested, the solution is to write this piece of code in Remember to change the role names and the urls. |
Beta Was this translation helpful? Give feedback.
For anybody interested, the solution is to write this piece of code in
superset_config.py:Remember to change the role names and the urls.