Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/asub 8279 broken login redirect 2.1.2 #2015

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
},
ecmaVersion: 2020,
sourceType: "module",
requireConfigFile: false,
},
plugins: ["jest", "jest-dom", "jsx-a11y", "react", "react-hooks", "testing-library"],
rules: {
Expand Down
18 changes: 10 additions & 8 deletions blocks/identity-block/components/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ const useLogin = ({
if (window?.location?.search) {
const searchParams = new URLSearchParams(window.location.search.substring(1));

//redirectURL could have additional params
// redirectURL could have additional params
const params = ["paymentMethodID"];
const aditionalParams = params.map((p) => {
const paramExist = searchParams.has(p)
if(paramExist){
return {[p]:searchParams.get(p)}
}
const aditionalParams = params.filter((p) => {
const paramExist = searchParams.has(p);

return paramExist;
})

const fullURL = searchParams.get("redirect") ? appendURLParams(searchParams.get("redirect"), aditionalParams.filter(item => item !== undefined)) : null;
Expand All @@ -37,7 +36,9 @@ const useLogin = ({
}

if (redirectToPreviousPage && document?.referrer) {
setRedirectToURL(document.referrer);
const redirectUrl = new URL(document.referrer);

setRedirectToURL(`${redirectUrl.pathname}${redirectUrl.search}`);
}
}, [redirectQueryParam, redirectToPreviousPage]);

Expand All @@ -56,6 +57,7 @@ const useLogin = ({
const checkLoggedInStatus = async () => {
const isLoggedIn = await Identity.isLoggedIn();
const validatedLoggedInPageLoc = validateURL(loggedInPageLocation);

if (isLoggedIn) {
if (isOIDC) {
loginByOIDC();
Expand All @@ -67,7 +69,7 @@ const useLogin = ({
if (Identity && !isAdmin) {
checkLoggedInStatus();
}
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin]);
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin, loginByOIDC, isOIDC]);

return {
loginRedirect: redirectQueryParam || redirectToURL,
Expand Down
12 changes: 8 additions & 4 deletions blocks/identity-block/components/login/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const defaultParams = {
loggedInPageLocation: "/account-2/",
};

const Test = (props) => {
function Test(props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this have to change here, but was left the same in the other PR?

Copy link
Contributor Author

@accbjt accbjt Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same question but for some reason on this PR it gave me some linting errors in the test file. Not sure what changed from the 2.1.2 and 2.3.0 but it gave me this linting error and I did a lint:fix and this is what it generated.

All I did was a cherry pick so the code should be the same.

const { loginRedirect } = useLogin({
...defaultParams,
...props,
Expand All @@ -29,12 +29,16 @@ const Test = (props) => {
</button>
</div>
);
};
}

describe("useLogin()", () => {
beforeEach(() => {
Object.defineProperty(window, "location", {
writable: true,
value: {
href: 'http://localhost',
search: ''
}
});
useIdentity.mockImplementation(() => ({
isInitialized: true,
Expand Down Expand Up @@ -68,14 +72,14 @@ describe("useLogin()", () => {
});

it("uses document referrer", async () => {
const referrerURL = "http://referrer.com";
const referrerURL = "http://referrer.com/article/1234";
Object.defineProperty(document, "referrer", {
value: referrerURL,
configurable: true,
});
await render(<Test />);
fireEvent.click(screen.getByRole("button"));
expect(window.location).toBe(referrerURL);
expect(window.location).toBe("/article/1234");
delete document.referrer;
});

Expand Down
6 changes: 6 additions & 0 deletions blocks/subscriptions-block/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,9 @@
@include scss.block-properties("paywall-subscription-dialog");
}
}

@media (min-width: 320px) and (max-width: 480px) {
.b-paywall__overlay {
inset-block-start: initial;
}
}
Loading