Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e065a7

Browse files
authored
Merge pull request#532 from raheeliftikhar5/refactor-redirect
Use SessionStorage for handling redirect after login/register
2 parents14e8dc2 +85c0499 commit5e065a7

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
exporttypeOutputChangeHandler<O>=(output:O)=>void;
1617
exporttypeEventTriggerHandler=(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
exporttypeAuthInviteInfo=InviteInfo&{invitationId:string};
2323
exporttypeAuthLocationState={inviteInfo?:AuthInviteInfo;thirdPartyAuthError?:boolean};
2424

25-
exportconstAuthSearchParams={
26-
loginType:"loginType",
27-
redirectUrl:"redirectUrl",
25+
exportenumAuthSearchParams{
26+
loginType="loginType",
27+
redirectUrl="redirectUrl",
28+
};
29+
30+
exporttypeAuthSearchParamsType={
31+
loginType:string|null,
32+
redirectUrl:string|null,
2833
};
2934

3035
exporttypeOauthRequestParam={

‎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
exportconstOAUTH_REDIRECT=`${USER_AUTH_URL}/oauth/redirect`;
4040
exportconstCAS_AUTH_REDIRECT=`${USER_AUTH_URL}/cas/redirect`;
4141
exportconstLDAP_AUTH_LOGIN_URL=`${USER_AUTH_URL}/ldap/login`;
42-
exportconstUSER_INFO_COMPLETION=`${USER_AUTH_URL}/completion`;
4342
exportconstINVITE_LANDING_URL="/invite/:invitationId";
4443
exportconstORG_AUTH_LOGIN_URL=`/org/:orgId/auth/login`;
4544
exportconstORG_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
letreplaceUrl=redirectUrl||BASE_URL;
8181
constbaseUrl=`${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+
constAuthSearchParamStorageKey="_temp_auth_search_params_";
185+
186+
exportconstsaveAuthSearchParams=(
187+
authSearchParams:AuthSearchParamsType
188+
)=>{
189+
sessionStorage.setItem(AuthSearchParamStorageKey,JSON.stringify(authSearchParams));
190+
}
191+
192+
exportconstloadAuthSearchParams=():AuthSearchParamsType|null=>{
193+
constauthParams=sessionStorage.getItem(AuthSearchParamStorageKey);
194+
if(!authParams)returnnull;
195+
returnJSON.parse(authParams);
196+
}
197+
198+
exportconstclearAuthSearchParams=()=>{
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
importReact,{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
constfetchUserAfterAuthSuccess=()=>{
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
importhistoryfrom"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
constThirdPartyLoginButtonWrapper=styled.div`
2120
button{
@@ -36,9 +35,7 @@ function ThirdPartyLoginButton(props: {
3635
label:string;
3736
}){
3837
const{ config, label}=props;
39-
constlocation=useLocation();
40-
constqueryParams=newURLSearchParams(location.search);
41-
constloginRedirectUrl=queryParams.get(AuthSearchParams.redirectUrl);
38+
constloginRedirectUrl=useRedirectUrl();
4239
constredirectUrl=getRedirectUrl(config.authType);
4340
constonLoginClick=()=>{
4441
conststate=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
functionvalidResponseData(response:AxiosResponse<ApiResponse>){
2829
returnresponse&&response.data&&response.data.data;
@@ -132,14 +133,14 @@ export function* logoutSaga(action: LogoutActionType) {
132133
try{
133134
letredirectURL=AUTH_LOGIN_URL;
134135
if(action.payload.notAuthorised){
135-
constcurrentUrl=window.location.href;
136-
redirectURL=`${AUTH_LOGIN_URL}?redirectUrl=${encodeURIComponent(currentUrl)}`;
136+
constcurrentUrl=window.location.href
137137
consturlObj=newURL(currentUrl);
138138
// Add loginType param for auto login jump
139139
constloginType=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
letisValidResponse=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
exportconstForceViewModeContext=React.createContext<boolean>(false);
2122

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

6162
exportfunctionuseRedirectUrl(){
62-
constlocation=useLocation();
63-
constqueryParams=newURLSearchParams(location.search);
64-
returnqueryParams.get(AuthSearchParams.redirectUrl);
63+
constauthSearchParams=loadAuthSearchParams()
64+
constredirectUrl=authSearchParams&&authSearchParams.redirectUrl
65+
returnredirectUrl&&decodeURIComponent(redirectUrl);
6566
}
6667

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp