Skip to content

Commit 466e97e

Browse files
refactor: use redirectUrl from sessionStorage
1 parent ae91db0 commit 466e97e

File tree

7 files changed

+14
-25
lines changed

7 files changed

+14
-25
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/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: 1 addition & 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";
@@ -80,12 +79,7 @@ export function authRespValidate(
8079
) {
8180
let replaceUrl = redirectUrl || BASE_URL;
8281
const baseUrl = `${window.location.protocol}//${window.location.host}`;
83-
if (infoCompleteCheck) {
84-
// need complete info
85-
replaceUrl = redirectUrl
86-
? `${USER_INFO_COMPLETION}?redirectUrl=${redirectUrl}`
87-
: USER_INFO_COMPLETION;
88-
}
82+
8983
if (doValidResponse(resp)) {
9084
onAuthSuccess?.();
9185
history.replace(replaceUrl.replace(baseUrl, ''));

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: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,10 @@ export function* logoutSaga(action: LogoutActionType) {
133133
try {
134134
let redirectURL = AUTH_LOGIN_URL;
135135
if (action.payload.notAuthorised) {
136-
const currentUrl = window.location.href;
137-
// redirectURL = `${AUTH_LOGIN_URL}`;
138-
// redirectURL = `${AUTH_LOGIN_URL}?redirectUrl=${encodeURIComponent(currentUrl)}`;
136+
const currentUrl = window.location.href
139137
const urlObj = new URL(currentUrl);
140138
// Add loginType param for auto login jump
141139
const loginType = urlObj.searchParams.get(AuthSearchParams.loginType);
142-
// if (loginType) {
143-
// redirectURL = redirectURL + `&${AuthSearchParams.loginType}=${loginType}`;
144-
// }
145140
saveAuthSearchParams({
146141
[AuthSearchParams.redirectUrl]: encodeURIComponent(currentUrl),
147142
[AuthSearchParams.loginType]: loginType

0 commit comments

Comments
 (0)