mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
refactor(frontend): error handling in the auth/local api route
This now uses the new error code for a disabled registration (403) and also handles error where the password is too weak (400). Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
0ec9edc07d
commit
45e70434c4
4 changed files with 11 additions and 5 deletions
|
@ -561,7 +561,8 @@
|
|||
"message": "Your account has been registered successfully. You can now log in with your username and password."
|
||||
},
|
||||
"error": {
|
||||
"registrationDisabled": "The registration is disabled",
|
||||
"passwordTooWeak": "The password is too weak.",
|
||||
"registrationDisabled": "The registration is disabled.",
|
||||
"usernameExisting": "There is already an account with this username.",
|
||||
"other": "There was an error while registering your account. Just try it again."
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -36,6 +36,7 @@ export const doLocalLogin = async (username: string, password: string): Promise<
|
|||
* @param username The username of the new user.
|
||||
* @param displayName The display name of the new user.
|
||||
* @param password The password of the new user.
|
||||
* @throws {RegisterError.PASSWORD_TOO_WEAK} when the backend deems the password too weak.
|
||||
* @throws {RegisterError.USERNAME_EXISTING} when there is already an existing user with the same username.
|
||||
* @throws {RegisterError.REGISTRATION_DISABLED} when the registration of local users has been disabled on the backend.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
|
@ -48,7 +49,8 @@ export const doLocalRegister = async (username: string, displayName: string, pas
|
|||
password
|
||||
})
|
||||
.withStatusCodeErrorMapping({
|
||||
400: RegisterError.REGISTRATION_DISABLED,
|
||||
400: RegisterError.PASSWORD_TOO_WEAK,
|
||||
403: RegisterError.REGISTRATION_DISABLED,
|
||||
409: RegisterError.USERNAME_EXISTING
|
||||
})
|
||||
.sendRequest()
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -12,6 +12,7 @@ export enum AuthError {
|
|||
|
||||
export enum RegisterError {
|
||||
USERNAME_EXISTING = 'usernameExisting',
|
||||
PASSWORD_TOO_WEAK = 'passwordTooWeak',
|
||||
REGISTRATION_DISABLED = 'registrationDisabled',
|
||||
OTHER = 'other'
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -22,6 +22,8 @@ export const RegisterError: React.FC<RegisterErrorProps> = ({ error }) => {
|
|||
|
||||
const errorMessageI18nKey = useMemo(() => {
|
||||
switch (error) {
|
||||
case RegisterErrorType.PASSWORD_TOO_WEAK:
|
||||
return 'login.register.error.passwordTooWeak'
|
||||
case RegisterErrorType.REGISTRATION_DISABLED:
|
||||
return 'login.register.error.registrationDisabled'
|
||||
case RegisterErrorType.USERNAME_EXISTING:
|
||||
|
|
Loading…
Reference in a new issue