Skip to content

Commit

Permalink
🐛 Fixed no redirect on Portal signin when trying to access newsletters (
Browse files Browse the repository at this point in the history
#20683)

ref https://linear.app/tryghost/issue/ENG-1464
- added redirect to sign in page when trying to access newsletter
management

If a user tries to access newsletter management when not logged in,
Portal requires sign in via magic link. This magic link didn't previous
redirect the user back to newsletter management, requiring some extra
clicks.
  • Loading branch information
9larsons authored Jul 29, 2024
1 parent f64820b commit a109b25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
5 changes: 4 additions & 1 deletion apps/portal/src/components/pages/AccountEmailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export default function AccountEmailPage() {
useEffect(() => {
if (!member) {
onAction('switchPage', {
page: 'signin'
page: 'signin',
pageData: {
redirect: window.location.href // This includes the search/fragment of the URL (#/portal/account) which is missing from the default referer header
}
});
}
}, [member, onAction]);
Expand Down
2 changes: 1 addition & 1 deletion apps/portal/src/components/pages/AccountEmailPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ describe('Account Email Page', () => {
newsletters: newsletterData
});
const {mockOnActionFn} = setup({site: siteData, member: null});
expect(mockOnActionFn).toHaveBeenCalledWith('switchPage', {page: 'signin'});
expect(mockOnActionFn).toHaveBeenCalledWith('switchPage', {page: 'signin', pageData: {redirect: window.location.href}});
});
});
29 changes: 0 additions & 29 deletions apps/portal/src/tests/EmailSubscriptionsFlow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,33 +254,4 @@ describe('Newsletter Subscriptions', () => {
expect(newsletter2Toggle).toHaveClass('gh-portal-toggle-checked');
});
});

// describe('navigating straight to /portal/account/newsletters', () => {
// it('shows the newsletter management page when signed in', async () => {
// const {popupFrame, triggerButton, queryAllByText, popupIframeDocument} = await setup({
// site: FixtureSite.singleTier.onlyFreePlanWithoutStripe,
// member: FixtureMember.subbedToNewsletter,
// newsletters: Newsletters
// });

// const manageSubscriptionsButton = within(popupIframeDocument).queryByRole('button', {name: 'Manage'});
// await userEvent.click(manageSubscriptionsButton);

// const newsletter1 = within(popupIframeDocument).queryAllByText('Newsletter 1');
// expect(newsletter1).toBeInTheDocument();
// });

// it('redirects to the sign in page when not signed in', async () => {
// const {popupFrame, queryByTitle, popupIframeDocument} = await setup({
// site: FixtureSite.singleTier.onlyFreePlanWithoutStripe,
// member: FixtureMember.subbedToNewsletter,
// newsletters: Newsletters
// }, true);

// // console.log(`popupFrame`, popupFrame);
// // console.log(`queryByTitle`, queryByTitle);
// // console.log(`popupIframeDocument`, popupIframeDocument);

// });
// });
});

0 comments on commit a109b25

Please sign in to comment.