PROBLEM STATEMENT
I'm working on a flask app that uses Stormpath for authentication. In my app I have two user groups: normal users
and admins
. After a user logs in, I'd like to redirect them to a specific page based on the group they belong to. So if a user is a normal user they'd be redirected to /dashboard
and if they are an admin, they'd be redirected to /admin_dashboard
. As of right now, I have STORMPATH_REDIRECT_URL = '/dashboard'
so every time they log in they get redirected to /dashboard
regardless of the group they belong to. How can I redirect them to a specific page based on their Stormpath group?
CURRENT CODE SNIPPETS:
Note: I am using the default Flask-Stormpath login views and the app allows social login through Google.
/app/__init__.py:
def create_app(config_name):
...
# App config here
...
stormpath_manager = StormpathManager()
stormpath_manager.init_app(app)
...
return app
/config.py:
class Config(Object):
...
STORMPATH_REDIRECT_URL = '/dashboard'
...
/app/dashboard/views.py:
@dashboard_blueprint.route('/dashboard')
@login_required
@groups_required(['normal-users'])
def dashboard():
return render_template('dashboard/index.html', title="Dashboard")
@dashboard_blueprint.route('/admin_dashboard')
@login_required
@groups_required(['admins'])
def admin_dashboard():
return render_template('dashboard/admin_index.html', title="Admin Dashboard")