fix(login): redirect correctly after login / registration
Docker / build-and-push (backend) (push) Has been cancelled
Docker / build-and-push (frontend) (push) Has been cancelled
E2E Tests / backend-sqlite (push) Has been cancelled
E2E Tests / backend-mariadb (push) Has been cancelled
E2E Tests / backend-postgres (push) Has been cancelled
Lint and check format / Lint files and check formatting (push) Has been cancelled
REUSE Compliance Check / reuse (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Static Analysis / Njsscan code scanning (push) Has been cancelled
Static Analysis / CodeQL analysis (javascript) (push) Has been cancelled
Run tests & build / Test and build with NodeJS 24 (push) Has been cancelled

We had two different approcaches to the redirect after the login / registration.
Because of this there were race conditions, and we sometimes got stuck on the redirect page.

Fixes #6467

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares
2026-04-23 23:31:51 +02:00
committed by Erik Michelson
parent 95f28442c3
commit c81dd893e7
3 changed files with 2 additions and 17 deletions
@@ -5,7 +5,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { NextPage } from 'next'
import { useRouter } from 'next/navigation'
import type { FormEvent } from 'react'
import React, { useCallback, useMemo, useState } from 'react'
import { Button, Form } from 'react-bootstrap'
@@ -21,7 +20,6 @@ import { PasswordAgainField } from '../../../common/fields/password-again-field'
import { RegisterInfos } from './register-infos'
import { RegisterError } from './register-error'
import { fetchAndSetUser } from '../../utils/fetch-and-set-user'
import { useGetPostLoginRedirectUrl } from '../../utils/use-get-post-login-redirect-url'
import { MAX_USERNAME_LENGTH, MIN_PASSWORD_LENGTH, MIN_USERNAME_LENGTH } from '@hedgedoc/commons'
/**
@@ -29,7 +27,6 @@ import { MAX_USERNAME_LENGTH, MIN_PASSWORD_LENGTH, MIN_USERNAME_LENGTH } from '@
*/
export const LocalRegisterForm: NextPage = () => {
useTranslation()
const router = useRouter()
const [username, setUsername] = useState('')
const [displayName, setDisplayName] = useState('')
@@ -38,18 +35,16 @@ export const LocalRegisterForm: NextPage = () => {
const [error, setError] = useState<ApiError>()
const { dispatchUiNotification } = useUiNotifications()
const postLoginRedirectUrl = useGetPostLoginRedirectUrl()
const doRegisterSubmit = useCallback(
(event: FormEvent) => {
doLocalRegister(username, displayName, password)
.then(() => fetchAndSetUser())
.then(() => dispatchUiNotification('login.register.success.title', 'login.register.success.message', {}))
.then(() => router.push(postLoginRedirectUrl))
.catch((error: ApiError) => setError(error))
event.preventDefault()
},
[username, displayName, password, dispatchUiNotification, router, postLoginRedirectUrl]
[username, displayName, password, dispatchUiNotification]
)
const ready = useMemo(() => {
@@ -51,12 +51,9 @@ export const NewUserCard: React.FC = () => {
profilePicture
})
.then(() => fetchAndSetUser())
.then(() => {
router.push('/')
})
.catch(showErrorNotificationBuilder('login.welcome.error'))
},
[pictureChoice, value, username, displayName, showErrorNotificationBuilder, router]
[pictureChoice, value, username, displayName, showErrorNotificationBuilder]
)
const cancelUserCreation = useCallback(() => {
@@ -60,7 +60,6 @@ export const UsernamePasswordLogin: React.FC<UsernamePasswordLoginProps> = ({
const onLoginSubmit = useCallback(
(event: FormEvent) => {
let redirect = false
setError(null)
setLoading(true)
lastUsernamePassword.current = [username, password]
@@ -69,15 +68,9 @@ export const UsernamePasswordLogin: React.FC<UsernamePasswordLoginProps> = ({
if (response.newUser) {
router.push('/new-user')
} else {
redirect = true
return fetchAndSetUser()
}
})
.then(() => {
if (redirect) {
router.push('/')
}
})
.catch((error: Error) => setError(errorMapping(error)))
.finally(() => setLoading(false))
event.preventDefault()