mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 09:16:30 -05:00
enhancement(login): add redirectBackTo parameter to login button
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
1207ce7690
commit
1199db4692
2 changed files with 21 additions and 7 deletions
|
@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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<ButtonProps, 'href'>
|
||||
|
||||
|
@ -26,6 +27,7 @@ export type SignInButtonProps = Omit<ButtonProps, 'href'>
|
|||
*/
|
||||
export const SignInButton: React.FC<SignInButtonProps> = ({ 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<SignInButtonProps> = ({ 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 (
|
||||
|
|
Loading…
Reference in a new issue