@@ -20,6 +20,16 @@ const useLogin = ({
20
20
const [ isAppleAuthSuccess , setIsAppleAuthSuccess ] = useState ( false ) ;
21
21
const { loginByOIDC } = useOIDCLogin ( ) ;
22
22
23
+ const setRedirectUrl = ( url ) => {
24
+ setCurrentRedirectToURL ( url ) ;
25
+ localStorage . setItem ( 'ArcXP_redirectUrl' , url ) ;
26
+ } ;
27
+
28
+ const getRedirectURL = ( ) => {
29
+ const localStorageRedirectUrl = localStorage . getItem ( 'ArcXP_redirectUrl' ) ;
30
+
31
+ return redirectQueryParam || localStorageRedirectUrl || currentRedirectToURL ;
32
+ } ;
23
33
24
34
useEffect ( ( ) => {
25
35
const askForloginWithApple = async ( code ) => {
@@ -57,13 +67,15 @@ const useLogin = ({
57
67
const redirectUrlLocation = new URL ( document . referrer ) ;
58
68
59
69
if ( searchParams . has ( 'reset_password' ) ) {
60
- setCurrentRedirectToURL ( `${ redirectURL } ${ redirectUrlLocation . search } ` ) ;
70
+ const newRedirectUrl = `${ redirectURL } ${ redirectUrlLocation . search } ` ;
71
+
72
+ setRedirectUrl ( newRedirectUrl ) ;
61
73
} else {
62
74
const newRedirectUrl = redirectUrlLocation . pathname . includes ( '/pagebuilder/' )
63
75
? redirectURL
64
76
: `${ redirectUrlLocation . pathname } ${ redirectUrlLocation . search } ` ;
65
77
66
- setCurrentRedirectToURL ( newRedirectUrl ) ;
78
+ setRedirectUrl ( newRedirectUrl ) ;
67
79
}
68
80
}
69
81
} , [ redirectQueryParam , redirectToPreviousPage , redirectURL ] ) ;
@@ -88,8 +100,11 @@ const useLogin = ({
88
100
if ( isOIDC ) {
89
101
loginByOIDC ( ) ;
90
102
} else {
91
- window . location = redirectQueryParam || validatedLoggedInPageLoc ;
103
+ const localStorageRedirectUrl = localStorage . getItem ( 'ArcXP_redirectUrl' ) ;
104
+
105
+ window . location = redirectQueryParam || localStorageRedirectUrl || validatedLoggedInPageLoc ;
92
106
}
107
+ localStorage . removeItem ( 'ArcXP_redirectUrl' ) ;
93
108
}
94
109
} ;
95
110
if ( Identity && ! isAdmin ) {
@@ -98,7 +113,7 @@ const useLogin = ({
98
113
} , [ Identity , redirectQueryParam , loggedInPageLocation , isAdmin , loginByOIDC , isOIDC , isAppleAuthSuccess ] ) ;
99
114
100
115
return {
101
- loginRedirect : redirectQueryParam || currentRedirectToURL ,
116
+ loginRedirect : getRedirectURL ( ) ,
102
117
} ;
103
118
} ;
104
119
0 commit comments