From 081081db5201ececfc01445d2d80347ddcf72b4d Mon Sep 17 00:00:00 2001 From: Mart van Santen <mart@greenhost.nl> Date: Tue, 14 Mar 2023 18:29:20 +0800 Subject: [PATCH] Redirect to dashboard as default if no redirect is set --- backend/web/login/login.py | 5 ++++- backend/web/static/base.js | 9 +++++++++ backend/web/templates/loggedin.html | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/web/login/login.py b/backend/web/login/login.py index 25f09a00..99851d29 100644 --- a/backend/web/login/login.py +++ b/backend/web/login/login.py @@ -146,7 +146,10 @@ def login(): name = " " + identity['traits']['name'] else: name = "" - return render_template("loggedin.html", api_url=KRATOS_PUBLIC_URL, dashboard_url=DASHBOARD_URL, name=name) + return render_template("loggedin.html", + api_url=KRATOS_PUBLIC_URL, + dashboard_url=DASHBOARD_URL, + name=name) # If we do not have a flow, get one. if not flow: diff --git a/backend/web/static/base.js b/backend/web/static/base.js index e7cab4a0..7838a87d 100644 --- a/backend/web/static/base.js +++ b/backend/web/static/base.js @@ -16,16 +16,25 @@ */ +// In default configuration the dashboed is on '/'. This can be overwritten +// before calling the scripts (and configured by the flask app +var dashboard_url = '/'; + // Check if an auth flow is configured and redirect to auth page in that // case. function check_flow_auth() { var state = Cookies.get('flow_state'); var url = Cookies.get('auth_url'); + // Redirect to the specified URL if (state == 'auth') { Cookies.set('flow_state', ''); window.location.href = url; + return; } + + // If no redirect is set, redirect to dashboard + window.location.href = dashboard_url + '/login'; } // Check if there if the flow is expired, if so, reset the cookie diff --git a/backend/web/templates/loggedin.html b/backend/web/templates/loggedin.html index aee728ef..51b35cd1 100644 --- a/backend/web/templates/loggedin.html +++ b/backend/web/templates/loggedin.html @@ -4,6 +4,7 @@ <script> var api_url = '{{ api_url }}'; + var dashboard_url = '{{ dashboard_url }}'; // Actions $(document).ready(function() { @@ -17,8 +18,7 @@ <div id="contentMessages"></div> <div id="contentWelcome"> - Welcome{{ name }}, you are logged in. + Welcome{{ name }}, you are logged in. We are redirecting you.... </div> - {% endblock %} -- GitLab