mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-09 05:41:57 -04:00
fix(login): prevent default for new user confirmation form event
Some checks failed
Run tests & build / Test and build with NodeJS 20 (push) Has been cancelled
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
E2E Tests / Build test build of frontend (push) Has been cancelled
Static Analysis / CodeQL analysis (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
E2E Tests / frontend-cypress (1) (push) Has been cancelled
E2E Tests / frontend-cypress (2) (push) Has been cancelled
E2E Tests / frontend-cypress (3) (push) Has been cancelled
Some checks failed
Run tests & build / Test and build with NodeJS 20 (push) Has been cancelled
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
E2E Tests / Build test build of frontend (push) Has been cancelled
Static Analysis / CodeQL analysis (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
E2E Tests / frontend-cypress (1) (push) Has been cancelled
E2E Tests / frontend-cypress (2) (push) Has been cancelled
E2E Tests / frontend-cypress (3) (push) Has been cancelled
The new user form which is shown when a new user logs in via an external auth provider did not include the event.preventDefault() statement. This meant that on submitting the form there was a race-condition between the JS code sending the data to the API and the browser reloading the page. Chromium-based browsers seem to handle events before handling page navigation, and because the form event initiates a page navigation on a successful API response it worked. Firefox seems to call the event handler and the page navigation in parallel, resulting in a loop on the new user form. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
a522380c4c
commit
055d2b6c5b
1 changed files with 16 additions and 11 deletions
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type { FormEvent } from 'react'
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { Button, Card, Form } from 'react-bootstrap'
|
||||
import { Trans } from 'react-i18next'
|
||||
|
@ -36,18 +37,22 @@ export const NewUserCard: React.FC = () => {
|
|||
const onChangeUsername = useOnInputChange(setUsername)
|
||||
const onChangeDisplayName = useOnInputChange(setDisplayName)
|
||||
|
||||
const submitUserdata = useCallback(() => {
|
||||
confirmPendingUser({
|
||||
username,
|
||||
displayName,
|
||||
profilePicture: pictureChoice === ProfilePictureChoice.PROVIDER ? value?.photoUrl : undefined
|
||||
})
|
||||
.then(() => fetchAndSetUser())
|
||||
.then(() => {
|
||||
router.push('/')
|
||||
const submitUserdata = useCallback(
|
||||
(event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
confirmPendingUser({
|
||||
username,
|
||||
displayName,
|
||||
profilePicture: pictureChoice === ProfilePictureChoice.PROVIDER ? value?.photoUrl : undefined
|
||||
})
|
||||
.catch(showErrorNotification('login.welcome.error'))
|
||||
}, [username, displayName, pictureChoice, router, showErrorNotification, value?.photoUrl])
|
||||
.then(() => fetchAndSetUser())
|
||||
.then(() => {
|
||||
router.push('/')
|
||||
})
|
||||
.catch(showErrorNotification('login.welcome.error'))
|
||||
},
|
||||
[username, displayName, pictureChoice, router, showErrorNotification, value?.photoUrl]
|
||||
)
|
||||
|
||||
const cancelUserCreation = useCallback(() => {
|
||||
cancelPendingUser()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue