GitHub user dosubot[bot] added a comment to the discussion: Redirect upon 
logging in

<!-- Answer -->
@carlosaran667 Apologies for the incorrect suggestion earlier. I did more 
research and found that the `CUSTOM_SECURITY_MANAGER` approach doesn't work for 
this because [v6 uses a unified 
`SupersetAuthView`](https://github.com/apache/superset/discussions/38199) that 
ignores custom auth view attributes.

The post-login flow in v6 is: `SupersetAuthView.login()` → 
`SupersetIndexView.index()` → 
[`Superset.welcome()`](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/views/core.py#L896-L922).
 The **recommended approach** is to override the `Superset.welcome()` endpoint 
using 
[`FLASK_APP_MUTATOR`](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/config.py#L1249-L1250):

```python
# superset_config.py
from flask import g, redirect, url_for
from flask_appbuilder import expose
from superset.views.core import Superset
from superset.utils.core import get_user_id

class CustomSuperset(Superset):
    @expose("/welcome/")
    def welcome(self):
        if not g.user or not get_user_id():
            from superset.extensions import appbuilder
            return redirect(appbuilder.get_url_for_login)
        
        # Role-based redirect logic
        user_roles = [role.name for role in g.user.roles]
        
        if 'Admin' in user_roles:
            return redirect('/dashboard/list/')
        elif 'Alpha' in user_roles:
            return redirect('/chart/list/')
        # Add more role conditions as needed
        
        # Fall back to default welcome behavior
        return super().welcome()

def FLASK_APP_MUTATOR(app):
    app.appbuilder.add_view_no_menu(CustomSuperset)
```

This [re-registers the Superset 
view](https://github.com/apache/superset/discussions/34530) with your custom 
`welcome()` method, which is the endpoint users land on after login. Adjust the 
role names and redirect URLs to match your requirements.


<!-- Dosu Comment Footer -->
*To reply, just mention 
[@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47b4-8f41-5fa3cceca6e1?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47b4-8f41-5fa3cceca6e1?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47b4-8f41-5fa3cceca6e1?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47b4-8f41-5fa3cceca6e1?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose)
 | [Hallucination](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47
 
b4-8f41-5fa3cceca6e1?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47b4-8f41-5fa3cceca6e1?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/b5a5c06d-7229-47b4-8f41-5fa3cceca6e1?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup>

[![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=%40carlosaran667%20Apologies%20for%20the%20incorrect%20suggestion%20earlier.%20I%20did%20more%20research%20and%20found%20that%20the%20%60CUSTOM_SECURITY_MANAGER%60%20approach%20doesn%27t%20work%20for%20this%20because%20%5Bv6%20uses%20a%20unified%20%60SupersetAuthView%60%5D%28https%3A//github.com/apache/superset/discussions/38199%29%20that%20ignores%20custom%20auth%20view%20attributes.%0A%0AThe%20post-login%20flow%20in%20v6%20is%3A%20%60SupersetAuthView.login%28%29%60%20%E2%86%92%20%60SupersetIndexView.index%28%29%60%20%E2%86%92%20%5B%60Superset.welcome%28%29%60%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/views/core.py%23L896
 
-L922%29.%20The%20%2A%2Arecommended%20approach%2A%2A%20is%20to%20override%20the%20%60Superset.welcome%28%29%60%20endpoint%20using%20%5B%60FLASK_APP_MUTATOR%60%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/config.py%23L1249-L1250%29%3A%0A%0A%60%60%60python%0A%23%20superset_config.py%0Afrom%20flask%20import%20g%2C%20redirect%2C%20url_for%0Afrom%20flask_appbuilder%20import%20expose%0Afrom%20superset.views.core%20import%20Superset%0Afrom%20superset.utils.core%20import%20get_user_id%0A%0Aclass%20CustomSuperset%28Superset%29%3A%0A%20%20%20%20%40expose%28%22/welcome/%22%29%0A%20%20%20%20def%20welcome%28self%29%3A%0A%20%20%20%20%20%20%20%20if%20not%20g.user%20or%20not%20get_user_id%28%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20from%20superset.extensions%20import%20appbuilder%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20redirect%28appbuilder.get_url_for_login%29%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%23%20Role-based%20redir
 
ect%20logic%0A%20%20%20%20%20%20%20%20user_roles%20%3D%20%5Brole.name%20for%20role%20in%20g.user.roles%5D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20if%20%27Admin%27%20in%20user_roles%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20redirect%28%27/dashboard/list/%27%29%0A%20%20%20%20%20%20%20%20elif%20%27Alpha%27%20in%20user_roles%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20redirect%28%27/chart/list/%27%29%0A%20%20%20%20%20%20%20%20%23%20Add%20more%20role%20conditions%20as%20needed%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%23%20Fall%20back%20to%20default%20welcome%20behavior%0A%20%20%20%20%20%20%20%20return%20super%28%29.welcome%28%29%0A%0Adef%20FLASK_APP_MUTATOR%28app%29%3A%0A%20%20%20%20app.appbuilder.add_view_no_menu%28CustomSuperset%29%0A%60%60%60%0A%0AThis%20%5Bre-registers%20the%20Superset%20view%5D%28https%3A//github.com/apache/superset/discussions/34530%29%20with%20your%20custom%20%60welcome%28%29%60%20method%2C%20which%20is%20the%20endpoint%20us
 
ers%20land%20on%20after%20login.%20Adjust%20the%20role%20names%20and%20redirect%20URLs%20to%20match%20your%20requirements.)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/38580)

GitHub link: 
https://github.com/apache/superset/discussions/38580#discussioncomment-16086232

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to