Skip to content

Commit

Permalink
fix: add redirection url on home page authorization (#594)
Browse files Browse the repository at this point in the history
* fix: add redirectionUrl on home page authorization

* fix: add redirection tests
  • Loading branch information
spaenleh authored Mar 28, 2024
1 parent bac7043 commit b7fdc4d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
40 changes: 40 additions & 0 deletions cypress/e2e/redirections.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { buildMainPath } from '@/config/paths';
import { USER_SWITCH_SIGN_IN_BUTTON_ID } from '@/config/selectors';

import { FOLDER_WITH_SUBFOLDER_ITEM } from '../fixtures/items';

describe('Home Page', () => {
describe('Logged out', () => {
beforeEach(() => {
cy.setUpApi({
currentMember: null,
});
});

it('Should redirect to auth with url parameter', () => {
cy.visit('/');

cy.url().should('include', `?url=`);
});
});
});
describe('Item page', () => {
describe('Logged out', () => {
beforeEach(() => {
cy.setUpApi({
items: FOLDER_WITH_SUBFOLDER_ITEM.items,
currentMember: null,
});

cy.visit(
buildMainPath({ rootId: FOLDER_WITH_SUBFOLDER_ITEM.items[0].id }),
);
});

it('Should redirect to auth with url parameter', () => {
cy.get(`#${USER_SWITCH_SIGN_IN_BUTTON_ID}`).should('be.visible').click();
cy.get(`[role="menuitem"]:visible`).click();
cy.url().should('include', `?url=`);
});
});
});
11 changes: 7 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {

import { Alert, Button, Stack, Typography } from '@mui/material';

import { saveUrlForRedirection } from '@graasp/sdk';
import { buildSignInPath, saveUrlForRedirection } from '@graasp/sdk';
import { CustomInitialLoader, withAuthorization } from '@graasp/ui';

import { SIGN_IN_PATH } from '@/config/constants';
import { DOMAIN } from '@/config/env';
import { AUTHENTICATION_HOST, DOMAIN } from '@/config/env';
import { HOME_PATH, buildContentPagePath, buildMainPath } from '@/config/paths';
import { useCurrentMemberContext } from '@/contexts/CurrentMemberContext';
import HomePage from '@/modules/pages/HomePage';
Expand Down Expand Up @@ -68,7 +67,11 @@ export const App = (): JSX.Element => {

const props = {
currentMember,
redirectionLink: SIGN_IN_PATH,
redirectionLink: buildSignInPath({
host: AUTHENTICATION_HOST,
// allows to go back to this page after login
redirectionUrl: window.location.href,
}),
onRedirect: () => {
// save current url for later redirection after sign in
saveUrlForRedirection(location.pathname, DOMAIN);
Expand Down
2 changes: 2 additions & 0 deletions src/config/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const HOME_PAGE_PAGINATION_ID = 'homePagePagination';
export const buildHomePaginationId = (page: number | null): string =>
`homePagination-${page}`;

export const USER_SWITCH_SIGN_IN_BUTTON_ID = 'userSwitchSignInButton';

export const APP_NAVIGATION_PLATFORM_SWITCH_ID = 'appNavigationPlatformSwitch';
export const APP_NAVIGATION_PLATFORM_SWITCH_BUTTON_IDS = {
[Platform.Builder]: 'appNavigationPlatformSwitchButtonBuilder',
Expand Down
8 changes: 7 additions & 1 deletion src/modules/item/ItemForbiddenScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Stack } from '@mui/material';
import { Button, ForbiddenContent } from '@graasp/ui';

import { usePlayerTranslation } from '@/config/i18n';
import { USER_SWITCH_SIGN_IN_BUTTON_ID } from '@/config/selectors';
import { useCurrentMemberContext } from '@/contexts/CurrentMemberContext';
import { PLAYER } from '@/langs/constants';
import UserSwitchWrapper from '@/modules/userSwitch/UserSwitchWrapper';
Expand All @@ -13,7 +14,12 @@ const ItemForbiddenScreen = (): JSX.Element => {
const { data: member } = useCurrentMemberContext();

const ButtonContent = (
<Button variant="outlined" startIcon={<AccountCircleIcon />}>
<Button
className="toto"
id={USER_SWITCH_SIGN_IN_BUTTON_ID}
variant="outlined"
startIcon={<AccountCircleIcon />}
>
{t(PLAYER.SIGN_IN_BUTTON_TEXT)}
</Button>
);
Expand Down

0 comments on commit b7fdc4d

Please sign in to comment.