Skip to content

Commit

Permalink
fix: set redirection for auth signin (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh authored Mar 28, 2024
1 parent 4cb2f14 commit 083c071
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/authentication.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ describe('Authentication', () => {
});
it('Home', () => {
cy.visit(HOME_PATH);
cy.url().should('equal', SIGN_IN_PATH);
cy.url().should('include', SIGN_IN_PATH);
cy.getCookie(CookieKeys.RedirectUrl, {
timeout: REQUEST_FAILURE_LOADING_TIME,
}).should('have.property', 'value', HOME_PATH);
});
it('Shared Items', () => {
cy.visit(SHARED_ITEMS_PATH);
cy.url().should('equal', SIGN_IN_PATH);
cy.url().should('include', SIGN_IN_PATH);
cy.getCookie(CookieKeys.RedirectUrl, {
timeout: REQUEST_FAILURE_LOADING_TIME,
}).should('have.property', 'value', SHARED_ITEMS_PATH);
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Header', () => {
// sign out
cy.get(`#${HEADER_MEMBER_MENU_BUTTON_ID}`).click();
cy.get(`#${HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID}`).click();
cy.url().should('equal', SIGN_IN_PATH);
cy.url().should('include', SIGN_IN_PATH);
});

// it('Switch users', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ export const mockSignInRedirection = (): void => {
cy.intercept(
{
method: HttpMethod.Get,
url: SIGN_IN_PATH,
pathname: new URL(SIGN_IN_PATH).pathname,
},
({ reply }) => {
reply(redirectionReply);
Expand Down
10 changes: 6 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Outlet, useLocation } from 'react-router';
import { Route, Routes } from 'react-router-dom';

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

import { DOMAIN } from '@/config/env';
import { SIGN_IN_PATH } from '@/config/externalPaths';
import { DOMAIN, GRAASP_AUTH_HOST } from '@/config/env';

import {
BOOKMARKED_ITEMS_PATH,
Expand Down Expand Up @@ -53,7 +52,10 @@ const App = (): JSX.Element => {

const withAuthorizationProps = {
currentMember,
redirectionLink: SIGN_IN_PATH,
redirectionLink: buildSignInPath({
host: GRAASP_AUTH_HOST,
redirectionUrl: window.location.toString(),
}),
onRedirect: () => {
// save current url for later redirection after sign in
saveUrlForRedirection(pathname, DOMAIN);
Expand Down
17 changes: 8 additions & 9 deletions src/components/common/UserSwitchWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CompleteMember } from '@graasp/sdk';
import { CompleteMember, buildSignInPath } from '@graasp/sdk';
import { UserSwitchWrapper as GraaspUserSwitch } from '@graasp/ui';

import { GRAASP_ACCOUNT_HOST } from '@/config/env';
import { SIGN_IN_PATH } from '@/config/externalPaths';
import { GRAASP_ACCOUNT_HOST, GRAASP_AUTH_HOST } from '@/config/env';
import { useBuilderTranslation } from '@/config/i18n';
import { mutations } from '@/config/queryClient';
import {
Expand All @@ -25,30 +24,30 @@ const UserSwitchWrapper = ({ ButtonContent }: Props): JSX.Element => {
const { data: member, isLoading } = useCurrentUserContext();
const { t: translateBuilder } = useBuilderTranslation();
const { mutateAsync: signOut } = mutations.useSignOut();
// todo: does not exist on mutations since we use httpOnly Cookie
// const { mutate: switchMember } = mutations.useSwitchMember();

const renderAvatar = (m?: CompleteMember | null) => (
<MemberAvatar id={m?.id} />
);

const redirectPath = buildSignInPath({
host: GRAASP_AUTH_HOST,
redirectionUrl: window.location.toString(),
});

return (
<GraaspUserSwitch
ButtonContent={ButtonContent}
signOut={signOut}
currentMember={member}
userMenuItems={[]}
isCurrentMemberLoading={isLoading}
// fix in query client
// switchMember={switchMember as any}
seeProfileText={translateBuilder(BUILDER.USER_SWITCH_PROFILE_BUTTON)}
signedOutTooltipText={translateBuilder(
BUILDER.USER_SWITCH_SIGNED_OUT_TOOLTIP,
)}
signOutText={translateBuilder(BUILDER.USER_SWITCH_SIGN_OUT_BUTTON)}
// switchMemberText={translateBuilder(BUILDER.USER_SWITCH_SWITCH_USER_TEXT)}
profilePath={GRAASP_ACCOUNT_HOST}
redirectPath={SIGN_IN_PATH}
redirectPath={redirectPath}
buttonId={HEADER_MEMBER_MENU_BUTTON_ID}
signInMenuItemId={HEADER_MEMBER_MENU_SIGN_IN_BUTTON_ID}
signOutMenuItemId={HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID}
Expand Down
6 changes: 1 addition & 5 deletions src/config/externalPaths.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Context, buildSignInPath } from '@graasp/sdk';
import { Context } from '@graasp/sdk';

import {
GRAASP_ANALYZER_HOST,
GRAASP_AUTH_HOST,
GRAASP_LIBRARY_HOST,
GRAASP_PLAYER_HOST,
} from './env';
Expand All @@ -15,9 +14,6 @@ export const buildGraaspBuilderView = (id: string): string =>
export const buildGraaspAnalyzerLink = (id: string): string =>
`${GRAASP_ANALYZER_HOST}/embedded/${id}`;

// signin page path from auth host
export const SIGN_IN_PATH = buildSignInPath({ host: GRAASP_AUTH_HOST });

export const HOST_MAP = {
[Context.Builder]: '/',
[Context.Library]: GRAASP_LIBRARY_HOST,
Expand Down

0 comments on commit 083c071

Please sign in to comment.