Skip to content

Commit ce5efd7

Browse files
committed
add localstorage to redirect url
1 parent 9ee574e commit ce5efd7

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

blocks/identity-block/components/login/index.jsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ const useLogin = ({
2020
const [isAppleAuthSuccess, setIsAppleAuthSuccess] = useState(false);
2121
const { loginByOIDC } = useOIDCLogin();
2222

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+
};
2333

2434
useEffect(() => {
2535
const askForloginWithApple = async (code) => {
@@ -57,13 +67,15 @@ const useLogin = ({
5767
const redirectUrlLocation = new URL(document.referrer);
5868

5969
if (searchParams.has('reset_password')) {
60-
setCurrentRedirectToURL(`${redirectURL}${redirectUrlLocation.search}`);
70+
const newRedirectUrl = `${redirectURL}${redirectUrlLocation.search}`;
71+
72+
setRedirectUrl(newRedirectUrl);
6173
} else {
6274
const newRedirectUrl = redirectUrlLocation.pathname.includes('/pagebuilder/')
6375
? redirectURL
6476
: `${redirectUrlLocation.pathname}${redirectUrlLocation.search}`;
6577

66-
setCurrentRedirectToURL(newRedirectUrl);
78+
setRedirectUrl(newRedirectUrl);
6779
}
6880
}
6981
}, [redirectQueryParam, redirectToPreviousPage, redirectURL]);
@@ -88,8 +100,11 @@ const useLogin = ({
88100
if (isOIDC) {
89101
loginByOIDC();
90102
} else {
91-
window.location = redirectQueryParam || validatedLoggedInPageLoc;
103+
const localStorageRedirectUrl = localStorage.getItem('ArcXP_redirectUrl');
104+
105+
window.location = redirectQueryParam || localStorageRedirectUrl || validatedLoggedInPageLoc;
92106
}
107+
localStorage.removeItem('ArcXP_redirectUrl');
93108
}
94109
};
95110
if (Identity && !isAdmin) {
@@ -98,7 +113,7 @@ const useLogin = ({
98113
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin, loginByOIDC, isOIDC, isAppleAuthSuccess]);
99114

100115
return {
101-
loginRedirect: redirectQueryParam || currentRedirectToURL,
116+
loginRedirect: getRedirectURL(),
102117
};
103118
};
104119

blocks/identity-block/components/social-sign-on/_children/AppleSignIn.jsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ function AppleSignIn({ socialSignOnIn, className }) {
1414
const { Identity } = useIdentity();
1515

1616
return (
17-
<Button
18-
id="apple-btn"
19-
variant="secondary-reverse"
20-
onClick={() => Identity.initAppleSignOn()}
21-
iconLeft={AppleIcon}
22-
className={`${className}__Apple`}
23-
>
24-
{socialSignOnIn !== SIGN_UP ? (
25-
<span>{phrases.t("identity-block.social-signOn-apple-login")}</span>
26-
) : (
27-
<span>{phrases.t("identity-block.social-signOn-apple-signUp")}</span>
28-
)}
29-
</Button>
17+
<Button
18+
id="apple-btn"
19+
variant="secondary-reverse"
20+
onClick={() => Identity.initAppleSignOn()}
21+
iconLeft={AppleIcon}
22+
className={`${className}__Apple`}
23+
>
24+
{socialSignOnIn !== SIGN_UP ? (
25+
<span>{phrases.t("identity-block.social-signOn-apple-login")}</span>
26+
) : (
27+
<span>{phrases.t("identity-block.social-signOn-apple-signUp")}</span>
28+
)}
29+
</Button>
3030
);
3131
}
3232

blocks/identity-block/components/social-sign-on/index.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import AppleSignIn from "./_children/AppleSignIn";
66
import useSocialSignIn from "./utils/useSocialSignIn";
77

88
const SocialSignOn = ({ className, onError, redirectURL, isOIDC, socialSignOnIn }) => {
9-
const { facebookAppId, googleClientId, appleTeamId, appleKeyId, appleUrlToReceiveAuthToken} = useSocialSignIn(redirectURL, isOIDC, socialSignOnIn, onError);
9+
const { facebookAppId, googleClientId, appleTeamId, appleKeyId, appleUrlToReceiveAuthToken } = useSocialSignIn(redirectURL, isOIDC, socialSignOnIn, onError);
1010
return (
1111
<section className={className}>
1212
{googleClientId ? <GoogleSignIn onError={onError} redirectURL={redirectURL} socialSignOnIn={socialSignOnIn} className={className} /> : null}
13-
{facebookAppId ? <FacebookSignIn socialSignOnIn={socialSignOnIn}/> : null}
13+
{facebookAppId ? <FacebookSignIn socialSignOnIn={socialSignOnIn} /> : null}
1414
{appleTeamId && appleKeyId && appleUrlToReceiveAuthToken ? <AppleSignIn socialSignOnIn={socialSignOnIn} className={className} /> : null}
1515
</section>
1616
);

blocks/identity-block/components/social-sign-on/utils/useSocialSignIn.js

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function useSocialSignIn(redirectURL, isOIDC, socialSignOnIn, onError = () => {}
5151
loginByOIDC();
5252
} else {
5353
const validatedURL = validateURL(redirectURL);
54+
5455
window.location = validatedURL;
5556
}
5657
}),

blocks/identity-block/features/account-management/default.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function AccountManagement({ customFields }) {
4343
const checkLoggedInStatus = () =>
4444
Identity.isLoggedIn().then((isLoggedIn) => {
4545
if (!isLoggedIn) {
46+
4647
window.location = redirectURL;
4748
return;
4849
}

blocks/identity-block/features/login/default.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const Login = ({ customFields }) => {
9090
loginByOIDC();
9191
} else {
9292
const validatedURL = validateURL(loginRedirect);
93+
9394
window.location = validatedURL;
9495
}
9596
})

blocks/identity-block/features/social-sign-on/default.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const SocialSignOnBlock = ({ customFields }) => {
6060

6161
return (
6262
<Stack className={BLOCK_CLASS_NAME} data-testid="social-sign-on-container">
63-
{!hideDiv ? <div className={`${BLOCK_CLASS_NAME}__dividerWithText`}>{phrases.t("identity-block.or")}</div> : null}
63+
{!hideDiv ? <div className={`${BLOCK_CLASS_NAME}__dividerWithText`}>{phrases.t("identity-block.or")}</div> : null}
6464
<GoogleSignInProvider>
6565
<SocialSignOn
6666
className={`${BLOCK_CLASS_NAME}__button-container`}

0 commit comments

Comments
 (0)