nuxt-users 1.49.1 → 1.49.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/server/api/nuxt-users/index.post.js +7 -1
- package/dist/runtime/server/services/registration.js +2 -2
- package/dist/runtime/server/utils/index.d.ts +1 -1
- package/dist/runtime/server/utils/index.js +1 -1
- package/dist/runtime/server/utils/user.d.ts +1 -0
- package/dist/runtime/server/utils/user.js +5 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createError, defineEventHandler, readBody } from "h3";
|
|
2
2
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
-
import { createUser } from "../../utils/index.js";
|
|
3
|
+
import { createUser, USER_EMAIL_ALREADY_EXISTS_MESSAGE } from "../../utils/index.js";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const { nuxtUsers } = useRuntimeConfig();
|
|
6
6
|
const options = nuxtUsers;
|
|
@@ -21,6 +21,12 @@ export default defineEventHandler(async (event) => {
|
|
|
21
21
|
return { user: newUser };
|
|
22
22
|
} catch (error) {
|
|
23
23
|
const message = error?.message || "Unknown error";
|
|
24
|
+
if (message === USER_EMAIL_ALREADY_EXISTS_MESSAGE) {
|
|
25
|
+
throw createError({
|
|
26
|
+
statusCode: 409,
|
|
27
|
+
statusMessage: message
|
|
28
|
+
});
|
|
29
|
+
}
|
|
24
30
|
const isClientError = typeof message === "string" && (message.startsWith("Invalid role") || message.startsWith("Role ") || message.startsWith("Password validation"));
|
|
25
31
|
throw createError({
|
|
26
32
|
statusCode: isClientError ? 400 : 500,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createTransport } from "nodemailer";
|
|
2
2
|
import crypto from "node:crypto";
|
|
3
3
|
import bcrypt from "bcrypt";
|
|
4
|
-
import { findUserByEmail, useDb } from "../utils/index.js";
|
|
4
|
+
import { findUserByEmail, useDb, USER_EMAIL_ALREADY_EXISTS_MESSAGE } from "../utils/index.js";
|
|
5
5
|
import { validatePassword, getPasswordValidationOptions } from "nuxt-users/utils";
|
|
6
6
|
const TOKEN_EXPIRATION_HOURS = 24;
|
|
7
7
|
export const registerUser = async (userData, options, baseUrl) => {
|
|
8
8
|
const existingUser = await findUserByEmail(userData.email, options);
|
|
9
9
|
if (existingUser) {
|
|
10
|
-
throw new Error(
|
|
10
|
+
throw new Error(USER_EMAIL_ALREADY_EXISTS_MESSAGE);
|
|
11
11
|
}
|
|
12
12
|
const passwordOptions = getPasswordValidationOptions(options);
|
|
13
13
|
const passwordValidation = validatePassword(userData.password, passwordOptions);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { useDb, checkTableExists, getConnector, closeAllDbConnections } from './db.js';
|
|
2
2
|
export { isBuildTime } from './build-time.js';
|
|
3
|
-
export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime, findUserById, updateUser, deleteUser } from './user.js';
|
|
3
|
+
export { createUser, USER_EMAIL_ALREADY_EXISTS_MESSAGE, findUserByEmail, updateUserPassword, getCurrentUserFromToken, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime, findUserById, updateUser, deleteUser } from './user.js';
|
|
4
4
|
export { createUsersTable } from './create-users-table.js';
|
|
5
5
|
export { createPersonalAccessTokensTable } from './create-personal-access-tokens-table.js';
|
|
6
6
|
export { createPasswordResetTokensTable } from './create-password-reset-tokens-table.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { useDb, checkTableExists, getConnector, closeAllDbConnections } from "./db.js";
|
|
2
2
|
export { isBuildTime } from "./build-time.js";
|
|
3
|
-
export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime, findUserById, updateUser, deleteUser } from "./user.js";
|
|
3
|
+
export { createUser, USER_EMAIL_ALREADY_EXISTS_MESSAGE, findUserByEmail, updateUserPassword, getCurrentUserFromToken, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime, findUserById, updateUser, deleteUser } from "./user.js";
|
|
4
4
|
export { createUsersTable } from "./create-users-table.js";
|
|
5
5
|
export { createPersonalAccessTokensTable } from "./create-personal-access-tokens-table.js";
|
|
6
6
|
export { createPasswordResetTokensTable } from "./create-password-reset-tokens-table.js";
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { useDb } from "./db.js";
|
|
2
2
|
import bcrypt from "bcrypt";
|
|
3
3
|
import { validatePassword, getPasswordValidationOptions, assertValidRole } from "nuxt-users/utils";
|
|
4
|
+
export const USER_EMAIL_ALREADY_EXISTS_MESSAGE = "A user with this email already exists";
|
|
4
5
|
export const createUser = async (userData, options) => {
|
|
5
6
|
const db = await useDb(options);
|
|
6
7
|
const usersTable = options.tables.users;
|
|
8
|
+
const existingUser = await findUserByEmail(userData.email, options);
|
|
9
|
+
if (existingUser) {
|
|
10
|
+
throw new Error(USER_EMAIL_ALREADY_EXISTS_MESSAGE);
|
|
11
|
+
}
|
|
7
12
|
const passwordOptions = getPasswordValidationOptions(options);
|
|
8
13
|
const passwordValidation = validatePassword(userData.password, passwordOptions);
|
|
9
14
|
if (!passwordValidation.isValid) {
|
package/package.json
CHANGED