Skip to content

Commit 5fc8cdd

Browse files
authored
Merge branch 'dev' into foldable-comps-sections
2 parents ad2e97e + 5e065a7 commit 5fc8cdd

File tree

9 files changed

+50
-30
lines changed

9 files changed

+50
-30
lines changed

client/packages/lowcoder/src/appView/AppViewInstance.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AppView } from "./AppView";
1111
import { API_STATUS_CODES } from "constants/apiConstants";
1212
import { AUTH_LOGIN_URL } from "constants/routesURL";
1313
import { AuthSearchParams } from "constants/authConstants";
14+
import { saveAuthSearchParams } from "@lowcoder-ee/pages/userAuth/authUtils";
1415

1516
export type OutputChangeHandler<O> = (output: O) => void;
1617
export type EventTriggerHandler = (eventName: string) => void;
@@ -71,9 +72,11 @@ export class AppViewInstance<I = any, O = any> {
7172
.then((i) => i.data)
7273
.catch((e) => {
7374
if (e.response?.status === API_STATUS_CODES.REQUEST_NOT_AUTHORISED) {
74-
window.location.href = `${webUrl}${AUTH_LOGIN_URL}?${
75-
AuthSearchParams.redirectUrl
76-
}=${encodeURIComponent(window.location.href)}`;
75+
saveAuthSearchParams({
76+
[AuthSearchParams.redirectUrl]: encodeURIComponent(window.location.href),
77+
[AuthSearchParams.loginType]: null,
78+
})
79+
window.location.href = `${webUrl}${AUTH_LOGIN_URL}`;
7780
}
7881
});
7982

client/packages/lowcoder/src/constants/authConstants.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ import {
2222
export type AuthInviteInfo = InviteInfo & { invitationId: string };
2323
export type AuthLocationState = { inviteInfo?: AuthInviteInfo; thirdPartyAuthError?: boolean };
2424

25-
export const AuthSearchParams = {
26-
loginType: "loginType",
27-
redirectUrl: "redirectUrl",
25+
export enum AuthSearchParams {
26+
loginType = "loginType",
27+
redirectUrl = "redirectUrl",
28+
};
29+
30+
export type AuthSearchParamsType = {
31+
loginType: string | null,
32+
redirectUrl: string | null,
2833
};
2934

3035
export type OauthRequestParam = {

client/packages/lowcoder/src/constants/routesURL.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const QR_CODE_OAUTH_URL = `${USER_AUTH_URL}/oauth/qrcode`;
3939
export const OAUTH_REDIRECT = `${USER_AUTH_URL}/oauth/redirect`;
4040
export const CAS_AUTH_REDIRECT = `${USER_AUTH_URL}/cas/redirect`;
4141
export const LDAP_AUTH_LOGIN_URL = `${USER_AUTH_URL}/ldap/login`;
42-
export const USER_INFO_COMPLETION = `${USER_AUTH_URL}/completion`;
4342
export const INVITE_LANDING_URL = "/invite/:invitationId";
4443
export const ORG_AUTH_LOGIN_URL = `/org/:orgId/auth/login`;
4544
export const ORG_AUTH_REGISTER_URL = `/org/:orgId/auth/register`;

client/packages/lowcoder/src/pages/userAuth/authUtils.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BASE_URL,
44
CAS_AUTH_REDIRECT,
55
OAUTH_REDIRECT,
6-
USER_INFO_COMPLETION,
76
} from "constants/routesURL";
87
import { AxiosPromise, AxiosResponse } from "axios";
98
import { ApiResponse } from "api/apiResponses";
@@ -16,6 +15,7 @@ import { createContext, useState } from "react";
1615
import { SystemConfig } from "constants/configConstants";
1716
import {
1817
AuthInviteInfo,
18+
AuthSearchParamsType,
1919
AuthSessionStoreParams,
2020
ThirdPartyAuthGoal,
2121
ThirdPartyAuthType,
@@ -79,12 +79,7 @@ export function authRespValidate(
7979
) {
8080
let replaceUrl = redirectUrl || BASE_URL;
8181
const baseUrl = `${window.location.protocol}//${window.location.host}`;
82-
if (infoCompleteCheck) {
83-
// need complete info
84-
replaceUrl = redirectUrl
85-
? `${USER_INFO_COMPLETION}?redirectUrl=${redirectUrl}`
86-
: USER_INFO_COMPLETION;
87-
}
82+
8883
if (doValidResponse(resp)) {
8984
onAuthSuccess?.();
9085
history.replace(replaceUrl.replace(baseUrl, ''));
@@ -185,3 +180,21 @@ export const getRedirectUrl = (authType: ThirdPartyAuthType) => {
185180
`${window.location.origin}${authType === "CAS" ? CAS_AUTH_REDIRECT : OAUTH_REDIRECT}`
186181
);
187182
};
183+
184+
const AuthSearchParamStorageKey = "_temp_auth_search_params_";
185+
186+
export const saveAuthSearchParams = (
187+
authSearchParams: AuthSearchParamsType
188+
) => {
189+
sessionStorage.setItem(AuthSearchParamStorageKey, JSON.stringify(authSearchParams));
190+
}
191+
192+
export const loadAuthSearchParams = ():AuthSearchParamsType | null => {
193+
const authParams = sessionStorage.getItem(AuthSearchParamStorageKey);
194+
if (!authParams) return null;
195+
return JSON.parse(authParams);
196+
}
197+
198+
export const clearAuthSearchParams = () => {
199+
sessionStorage.removeItem(AuthSearchParamStorageKey);
200+
}

client/packages/lowcoder/src/pages/userAuth/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Redirect, Route, Switch, useLocation, useParams } from "react-router-do
33
import React, { useEffect, useMemo } from "react";
44
import { useSelector, useDispatch } from "react-redux";
55
import { selectSystemConfig } from "redux/selectors/configSelectors";
6-
import { AuthContext } from "pages/userAuth/authUtils";
6+
import { AuthContext, clearAuthSearchParams } from "pages/userAuth/authUtils";
77
import { AuthRoutes } from "@lowcoder-ee/constants/authConstants";
88
import { AuthLocationState } from "constants/authConstants";
99
import { ProductLoading } from "components/ProductLoading";
@@ -37,6 +37,7 @@ export default function UserAuth() {
3737

3838
const fetchUserAfterAuthSuccess = () => {
3939
dispatch(fetchUserAction());
40+
clearAuthSearchParams();
4041
}
4142

4243
return (

client/packages/lowcoder/src/pages/userAuth/thirdParty/authenticator/abstractAuthenticator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export abstract class AbstractAuthenticator {
3939
authRespValidate(
4040
resp,
4141
this.needInfoCheck(this.authParams.sourceType),
42-
this.authParams.afterLoginRedirect,
42+
getSafeAuthRedirectURL(this.authParams.afterLoginRedirect),
4343
onAuthSuccess,
4444
);
4545
})

client/packages/lowcoder/src/pages/userAuth/thirdParty/thirdPartyAuth.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {
2-
AuthSearchParams,
32
OAuthLocationState,
43
ThirdPartyAuthGoal,
54
ThirdPartyConfigType,
65
} from "constants/authConstants";
7-
import { CommonGrayLabel, WhiteLoading } from "lowcoder-design";
8-
import { useLocation } from "react-router-dom";
6+
import { WhiteLoading } from "lowcoder-design";
97
import history from "util/history";
108
import { LoginLogoStyle, LoginLabelStyle, StyledLoginButton } from "pages/userAuth/authComponents";
119
import { useSelector } from "react-redux";
@@ -16,6 +14,7 @@ import styled from "styled-components";
1614
import { trans } from "i18n";
1715
import { geneAuthStateAndSaveParam, getAuthUrl, getRedirectUrl } from "pages/userAuth/authUtils";
1816
import { Divider } from "antd";
17+
import { useRedirectUrl } from "util/hooks";
1918

2019
const ThirdPartyLoginButtonWrapper = styled.div`
2120
button{
@@ -36,9 +35,7 @@ function ThirdPartyLoginButton(props: {
3635
label: string;
3736
}) {
3837
const { config, label } = props;
39-
const location = useLocation();
40-
const queryParams = new URLSearchParams(location.search);
41-
const loginRedirectUrl = queryParams.get(AuthSearchParams.redirectUrl);
38+
const loginRedirectUrl = useRedirectUrl();
4239
const redirectUrl = getRedirectUrl(config.authType);
4340
const onLoginClick = () => {
4441
const state = geneAuthStateAndSaveParam(

client/packages/lowcoder/src/redux/sagas/userSagas.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { defaultUser } from "constants/userConstants";
2323
import { messageInstance } from "lowcoder-design";
2424

2525
import { AuthSearchParams } from "constants/authConstants";
26+
import { saveAuthSearchParams } from "pages/userAuth/authUtils";
2627

2728
function validResponseData(response: AxiosResponse<ApiResponse>) {
2829
return response && response.data && response.data.data;
@@ -132,14 +133,14 @@ export function* logoutSaga(action: LogoutActionType) {
132133
try {
133134
let redirectURL = AUTH_LOGIN_URL;
134135
if (action.payload.notAuthorised) {
135-
const currentUrl = window.location.href;
136-
redirectURL = `${AUTH_LOGIN_URL}?redirectUrl=${encodeURIComponent(currentUrl)}`;
136+
const currentUrl = window.location.href
137137
const urlObj = new URL(currentUrl);
138138
// Add loginType param for auto login jump
139139
const loginType = urlObj.searchParams.get(AuthSearchParams.loginType);
140-
if (loginType) {
141-
redirectURL = redirectURL + `&${AuthSearchParams.loginType}=${loginType}`;
142-
}
140+
saveAuthSearchParams({
141+
[AuthSearchParams.redirectUrl]: encodeURIComponent(currentUrl),
142+
[AuthSearchParams.loginType]: loginType
143+
});
143144
}
144145
let isValidResponse = true;
145146
if (!action.payload.notAuthorised) {

client/packages/lowcoder/src/util/hooks.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { checkIsMobile } from "util/commonUtils";
1616
import { EditorContext } from "comps/editorState";
1717
import { getDataSourceStructures } from "redux/selectors/datasourceSelectors";
1818
import { DatasourceStructure } from "api/datasourceApi";
19+
import { loadAuthSearchParams } from "pages/userAuth/authUtils";
1920

2021
export const ForceViewModeContext = React.createContext<boolean>(false);
2122

@@ -59,9 +60,9 @@ export function useApplicationId() {
5960
}
6061

6162
export function useRedirectUrl() {
62-
const location = useLocation();
63-
const queryParams = new URLSearchParams(location.search);
64-
return queryParams.get(AuthSearchParams.redirectUrl);
63+
const authSearchParams = loadAuthSearchParams()
64+
const redirectUrl = authSearchParams && authSearchParams.redirectUrl
65+
return redirectUrl && decodeURIComponent(redirectUrl);
6566
}
6667

6768
export function useFixedDelay(callback: () => Promise<unknown>, delay: number | null) {

0 commit comments

Comments
 (0)