diff --git a/frontend/cypress/e2e/signInButton.spec.ts b/frontend/cypress/e2e/signInButton.spec.ts index 6adf5ab2b..bc1dde71c 100644 --- a/frontend/cypress/e2e/signInButton.spec.ts +++ b/frontend/cypress/e2e/signInButton.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -51,7 +51,10 @@ describe('When logged-out ', () => { type: AuthProviderType.LOCAL } ]) - cy.getByCypressId('sign-in-button').should('be.visible').parent().should('have.attr', 'href', '/login') + cy.getByCypressId('sign-in-button') + .should('be.visible') + .parent() + .should('have.attr', 'href', '/login?redirectBackTo=/history') }) it('sign-in button points to login route: ldap', () => { @@ -62,7 +65,10 @@ describe('When logged-out ', () => { providerName: 'cy LDAP' } ]) - cy.getByCypressId('sign-in-button').should('be.visible').parent().should('have.attr', 'href', '/login') + cy.getByCypressId('sign-in-button') + .should('be.visible') + .parent() + .should('have.attr', 'href', '/login?redirectBackTo=/history') }) }) @@ -91,7 +97,10 @@ describe('When logged-out ', () => { type: AuthProviderType.GOOGLE } ]) - cy.getByCypressId('sign-in-button').should('be.visible').parent().should('have.attr', 'href', '/login') + cy.getByCypressId('sign-in-button') + .should('be.visible') + .parent() + .should('have.attr', 'href', '/login?redirectBackTo=/history') }) }) @@ -105,7 +114,10 @@ describe('When logged-out ', () => { type: AuthProviderType.LOCAL } ]) - cy.getByCypressId('sign-in-button').should('be.visible').parent().should('have.attr', 'href', '/login') + cy.getByCypressId('sign-in-button') + .should('be.visible') + .parent() + .should('have.attr', 'href', '/login?redirectBackTo=/history') }) }) }) diff --git a/frontend/src/components/landing-layout/navigation/sign-in-button.tsx b/frontend/src/components/landing-layout/navigation/sign-in-button.tsx index 3340adb80..e76f5be12 100644 --- a/frontend/src/components/landing-layout/navigation/sign-in-button.tsx +++ b/frontend/src/components/landing-layout/navigation/sign-in-button.tsx @@ -14,6 +14,7 @@ import type { ButtonProps } from 'react-bootstrap/Button' import { Trans } from 'react-i18next' import { filterOneClickProviders } from '../../login-page/utils/filter-one-click-providers' import { getOneClickProviderMetadata } from '../../login-page/one-click/get-one-click-provider-metadata' +import { usePathname } from 'next/navigation' export type SignInButtonProps = Omit @@ -26,6 +27,7 @@ export type SignInButtonProps = Omit */ export const SignInButton: React.FC = ({ variant, ...props }) => { const authProviders = useFrontendConfig().authProviders + const pathname = usePathname() const loginLink = useMemo(() => { const oneClickProviders = filterOneClickProviders(authProviders) @@ -33,8 +35,8 @@ export const SignInButton: React.FC = ({ variant, ...props }) const metadata = getOneClickProviderMetadata(oneClickProviders[0]) return metadata.url } - return '/login' - }, [authProviders]) + return `/login?redirectBackTo=${pathname}` + }, [authProviders, pathname]) const buttonTitle = useTranslatedText('login.signIn') return (