msyavuz commented on code in PR #35345:
URL: https://github.com/apache/superset/pull/35345#discussion_r2392496589
##########
superset-frontend/src/pages/Login/index.tsx:
##########
@@ -82,6 +82,26 @@ export default function Login() {
const dispatch = useDispatch();
const bootstrapData = getBootstrapData();
+ const nextUrl = useMemo(() => {
+ try {
+ const params = new URLSearchParams(window.location.search);
+ return params.get('next') || '';
+ } catch (_error) {
+ return '';
+ }
+ }, []);
+
+ const loginEndpoint = useMemo(
+ () => (nextUrl ? `/login/?next=${encodeURIComponent(nextUrl)}` :
'/login/'),
+ [nextUrl],
+ );
+
+ const buildProviderLoginUrl = (providerName: string) => {
+ const base = `/login/${providerName}`;
+ return nextUrl
+ ? `${base}${base.includes('?') ? '&' :
'?'}next=${encodeURIComponent(nextUrl)}`
+ : base;
+ };
Review Comment:
It looks like this might be a bit more DRY but it's just a nit
##########
superset/views/utils.py:
##########
@@ -58,6 +59,33 @@
REJECTED_FORM_DATA_KEYS = ["js_tooltip", "js_onclick_href",
"js_data_mutator"]
+def redirect_to_login(next_target: str | None = None) -> FlaskResponse:
+ """Return a redirect response to the login view, preserving target URL.
+
+ When ``next_target`` is ``None`` the current request path (including query
+ string) is used, provided a request context is available. The resulting URL
+ always remains relative, mirroring Flask-AppBuilder expectations.
+ """
+
+ login_url = appbuilder.get_url_for_login
+ parsed = parse.urlparse(login_url)
+ query = parse.parse_qs(parsed.query, keep_blank_values=True)
+
+ target = next_target
+ if target is None and has_request_context():
+ if request.query_string:
+ target = request.full_path.rstrip("?")
+ else:
+ target = request.path
+
+ if target:
+ query["next"] = [target]
+
+ encoded_query = parse.urlencode(query, doseq=True)
+ redirect_url = parse.urlunparse(parsed._replace(query=encoded_query))
Review Comment:
Can we use anything else than the private method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]