Merge branch 'dev' into feat/password-editing

This commit is contained in:
limes
2026-08-30 20:22:24 +02:00
31 changed files with 219 additions and 179 deletions

View File

@@ -21,11 +21,12 @@ const errors: Record<string, ApiErrorCodes> = {
'INVALID_ARGUMENT: Two or more punctuation characters cannot be used in a row': 'USERNAME_INVALID_CHARS',
'INVALID_ARGUMENT: PNID already in use': 'USERNAME_IN_USE',
'INVALID_ARGUMENT: Mii name too long': 'MIINAME_TOO_LONG',
'INVALID_ARGUMENT: Password must be between 6 and 16 characters long': 'INVALID_PASSWORD_LENGTH',
'INVALID_ARGUMENT: Password cannot be the same as username': 'INVALID_PASSWORD_USERNAME',
'INVALID_ARGUMENT: Password must have combination of letters, numbers, and/or punctuation characters': 'INVALID_PASSWORD_COMBOS',
'INVALID_ARGUMENT: Password may not have 3 repeating characters': 'INVALID_PASSWORD_REPEATING',
'INVALID_ARGUMENT: Passwords do not match': 'INVALID_PASSWORD_NO_MATCH'
'INVALID_ARGUMENT: Password must be between 6 and 16 characters long': 'PASSWORD_INVALID_LENGTH',
'INVALID_ARGUMENT: Password cannot be the same as username': 'PASSWORD_NOT_USERNAME',
'INVALID_ARGUMENT: Password must have combination of letters, numbers, and/or punctuation characters': 'PASSWORD_NEEDS_CHARS',
'INVALID_ARGUMENT: Password may not have 3 repeating characters': 'PASSWORD_REPEATED_CHARS',
'INVALID_ARGUMENT: Passwords do not match': 'PASSWORDS_DO_NOT_MATCH'
};
function getCutoffDateForAge(today: Date, age: number) {

View File

@@ -1,19 +1,45 @@
import { ResetPasswordSchema } from '~~/shared/api-types';
import type { ApiErrorCodes } from '~~/shared/errors';
const errors: Record<string, ApiErrorCodes> = {
'Missing token': 'INVALID_INPUT',
'Invalid token': 'INVALID_INPUT',
'Token expired': 'INVALID_INPUT',
'Invalid token. No user found': 'INVALID_INPUT',
'Must enter a password': 'PASSWORD_INVALID_LENGTH',
'Password is too long': 'PASSWORD_INVALID_LENGTH',
'Password is too short': 'PASSWORD_INVALID_LENGTH',
'Password cannot be the same as username': 'PASSWORD_NOT_USERNAME',
'Password must have combination of letters, numbers, and/or punctuation characters': 'PASSWORD_NEEDS_CHARS',
'Password may not have 3 repeating characters': 'PASSWORD_REPEATED_CHARS',
'Passwords do not match': 'PASSWORDS_DO_NOT_MATCH'
};
export default defineEventHandler(async (event): Promise<void> => {
const body = await readZodBody(event, ResetPasswordSchema);
const apiFetch = useHttpApi(event);
// The GRPC version requires a login token, which the user doesnt have when resetting password, so we're using the HTTP api
await apiFetch('/v1/reset-password', {
method: 'POST',
body: JSON.stringify({
password: body.password,
password_confirm: body.passwordConfirm,
token: body.resetToken
}),
headers: {
'Content-type': 'application/json'
try {
await apiFetch('/v1/reset-password', {
method: 'POST',
body: JSON.stringify({
password: body.password,
password_confirm: body.passwordConfirm,
token: body.resetToken
}),
headers: {
'Content-type': 'application/json'
}
});
} catch (err: any) {
const data = err?.data;
let errorCode: ApiErrorCodes = 'UNHANDLED_ERROR';
if (typeof data === 'object' && data?.error) {
errorCode = errors[data.error] ?? 'UNHANDLED_ERROR';
}
});
throw createApiError(errorCode);
}
});