nuxt-users 1.1.3 → 1.1.5
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/CHANGELOG.md +86 -0
- package/README.md +12 -0
- package/dist/cli.mjs +33 -346
- package/dist/module.d.mts +1 -49
- package/dist/module.d.ts +1 -49
- package/dist/module.json +2 -2
- package/dist/runtime/components/ForgotPasswordForm.vue +21 -23
- package/dist/runtime/components/LoginForm.vue +42 -30
- package/dist/runtime/components/LoginForm.vue.d.ts +8 -8
- package/dist/runtime/components/ResetPasswordForm.vue +40 -33
- package/dist/runtime/plugin.js +1 -1
- package/dist/runtime/server/api/login.post.js +1 -1
- package/dist/runtime/server/services/password.js +1 -2
- package/dist/shared/nuxt-users.Dtq4WcpY.d.mts +58 -0
- package/dist/shared/nuxt-users.Dtq4WcpY.d.ts +58 -0
- package/dist/shared/nuxt-users.eSQUrS6l.mjs +333 -0
- package/dist/utils.d.mts +37 -0
- package/dist/utils.d.ts +37 -0
- package/dist/utils.mjs +3 -0
- package/package.json +49 -33
- package/dist/chunks/better-sqlite3.mjs +0 -45
- package/dist/chunks/mysql2.mjs +0 -49
- package/dist/chunks/postgresql.mjs +0 -58
- package/dist/shared/nuxt-users.C9d5M6B1.mjs +0 -31
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import bcrypt from 'bcrypt';
|
|
2
|
+
import { createDatabase } from 'db0';
|
|
3
|
+
|
|
4
|
+
const getConnector = async (name) => {
|
|
5
|
+
try {
|
|
6
|
+
switch (name) {
|
|
7
|
+
case "mysql":
|
|
8
|
+
return (await import('db0/connectors/mysql2')).default;
|
|
9
|
+
case "postgresql":
|
|
10
|
+
return (await import('db0/connectors/postgresql')).default;
|
|
11
|
+
case "sqlite":
|
|
12
|
+
return (await import('db0/connectors/better-sqlite3')).default;
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unsupported database connector: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof Error && error.message.includes("Cannot resolve")) {
|
|
18
|
+
throw new Error(`Database connector "${name}" not found. Please install the required peer dependency:
|
|
19
|
+
- For sqlite: yarn add better-sqlite3
|
|
20
|
+
- For mysql: yarn add mysql2
|
|
21
|
+
- For postgresql: yarn add pg`);
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const useDb = async (options) => {
|
|
27
|
+
const connectorName = options.connector.name;
|
|
28
|
+
const connector = await getConnector(connectorName);
|
|
29
|
+
const connectorOptions = { ...options.connector.options };
|
|
30
|
+
if (connectorName !== "sqlite") {
|
|
31
|
+
delete connectorOptions.path;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return createDatabase(connector(connectorOptions));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn(`[Nuxt Users DB] \u26A0\uFE0F Failed to connect to ${connectorName} database:`, error instanceof Error ? error.message : "Unknown error");
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const checkTableExists = async (options, tableName) => {
|
|
41
|
+
try {
|
|
42
|
+
const db = await useDb(options);
|
|
43
|
+
await db.sql`SELECT 1 FROM {${tableName}} LIMIT 1`;
|
|
44
|
+
return true;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const createUser = async (userData, options) => {
|
|
51
|
+
const db = await useDb(options);
|
|
52
|
+
const usersTable = options.tables.users;
|
|
53
|
+
const hashedPassword = await bcrypt.hash(userData.password, 10);
|
|
54
|
+
await db.sql`
|
|
55
|
+
INSERT INTO {${usersTable}} (email, name, password, created_at, updated_at)
|
|
56
|
+
VALUES (${userData.email}, ${userData.name}, ${hashedPassword}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
|
57
|
+
`;
|
|
58
|
+
const result = await db.sql`SELECT id, email, name, created_at, updated_at FROM {${usersTable}} WHERE email = ${userData.email}`;
|
|
59
|
+
if (result.rows.length === 0) {
|
|
60
|
+
throw new Error("Failed to retrieve created user.");
|
|
61
|
+
}
|
|
62
|
+
const user = result.rows[0];
|
|
63
|
+
return {
|
|
64
|
+
id: user.id,
|
|
65
|
+
email: user.email,
|
|
66
|
+
name: user.name,
|
|
67
|
+
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
68
|
+
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const findUserByEmail = async (email, options) => {
|
|
72
|
+
const db = await useDb(options);
|
|
73
|
+
const usersTable = options.tables.users;
|
|
74
|
+
const result = await db.sql`SELECT * FROM {${usersTable}} WHERE email = ${email}`;
|
|
75
|
+
if (result.rows.length === 0) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const user = result.rows[0];
|
|
79
|
+
return {
|
|
80
|
+
id: user.id,
|
|
81
|
+
email: user.email,
|
|
82
|
+
name: user.name,
|
|
83
|
+
password: user.password,
|
|
84
|
+
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
85
|
+
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const updateUserPassword = async (email, newPassword, options) => {
|
|
89
|
+
const db = await useDb(options);
|
|
90
|
+
const usersTable = options.tables.users;
|
|
91
|
+
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
92
|
+
await db.sql`
|
|
93
|
+
UPDATE {${usersTable}}
|
|
94
|
+
SET password = ${hashedPassword}, updated_at = CURRENT_TIMESTAMP
|
|
95
|
+
WHERE email = ${email}
|
|
96
|
+
`;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const createUsersTable = async (options) => {
|
|
100
|
+
const connectorName = options.connector.name;
|
|
101
|
+
const db = await useDb(options);
|
|
102
|
+
const tableName = options.tables.users;
|
|
103
|
+
console.log(`[DB:Create ${connectorName} Users Table] Creating ${tableName}...`);
|
|
104
|
+
if (connectorName === "sqlite") {
|
|
105
|
+
await db.sql`
|
|
106
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
107
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
108
|
+
email TEXT NOT NULL UNIQUE,
|
|
109
|
+
name TEXT NOT NULL,
|
|
110
|
+
password TEXT NOT NULL,
|
|
111
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
112
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
113
|
+
)
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
if (connectorName === "mysql") {
|
|
117
|
+
await db.sql`
|
|
118
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
119
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
120
|
+
email VARCHAR(255) NOT NULL UNIQUE,
|
|
121
|
+
name VARCHAR(255) NOT NULL,
|
|
122
|
+
password VARCHAR(255) NOT NULL,
|
|
123
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
124
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
125
|
+
)
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
if (connectorName === "postgresql") {
|
|
129
|
+
await db.sql`
|
|
130
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
131
|
+
id SERIAL PRIMARY KEY,
|
|
132
|
+
email VARCHAR(255) NOT NULL UNIQUE,
|
|
133
|
+
name VARCHAR(255) NOT NULL,
|
|
134
|
+
password VARCHAR(255) NOT NULL,
|
|
135
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
136
|
+
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
137
|
+
)
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
console.log(`[DB:Create ${connectorName} Users Table] Fields: id, email, name, password, created_at, updated_at \u2705`);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const createPersonalAccessTokensTable = async (options) => {
|
|
144
|
+
const connectorName = options.connector.name;
|
|
145
|
+
const db = await useDb(options);
|
|
146
|
+
const tableName = options.tables.personalAccessTokens;
|
|
147
|
+
console.log(`[DB:Create Personal Access Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
|
|
148
|
+
if (connectorName === "sqlite") {
|
|
149
|
+
await db.sql`
|
|
150
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
151
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
152
|
+
tokenable_type TEXT NOT NULL,
|
|
153
|
+
tokenable_id INTEGER NOT NULL,
|
|
154
|
+
name TEXT NOT NULL,
|
|
155
|
+
token TEXT NOT NULL UNIQUE,
|
|
156
|
+
abilities TEXT,
|
|
157
|
+
last_used_at DATETIME,
|
|
158
|
+
expires_at DATETIME,
|
|
159
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
160
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
161
|
+
)
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
if (connectorName === "mysql") {
|
|
165
|
+
await db.sql`
|
|
166
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
167
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
168
|
+
tokenable_type VARCHAR(255) NOT NULL,
|
|
169
|
+
tokenable_id INT NOT NULL,
|
|
170
|
+
name VARCHAR(255) NOT NULL,
|
|
171
|
+
token VARCHAR(255) NOT NULL UNIQUE,
|
|
172
|
+
abilities TEXT,
|
|
173
|
+
last_used_at DATETIME,
|
|
174
|
+
expires_at DATETIME,
|
|
175
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
176
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
177
|
+
)
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
if (connectorName === "postgresql") {
|
|
181
|
+
await db.sql`
|
|
182
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
183
|
+
id SERIAL PRIMARY KEY,
|
|
184
|
+
tokenable_type VARCHAR(255) NOT NULL,
|
|
185
|
+
tokenable_id INT NOT NULL,
|
|
186
|
+
name VARCHAR(255) NOT NULL,
|
|
187
|
+
token VARCHAR(255) NOT NULL UNIQUE,
|
|
188
|
+
abilities TEXT,
|
|
189
|
+
last_used_at TIMESTAMPTZ,
|
|
190
|
+
expires_at TIMESTAMPTZ,
|
|
191
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
192
|
+
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
193
|
+
)
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
console.log(`[DB:Create Personal Access Tokens ${connectorName} Table] Fields: id, tokenable_type, tokenable_id, name, token, abilities, last_used_at, expires_at, created_at, updated_at \u2705`);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const createPasswordResetTokensTable = async (options) => {
|
|
200
|
+
const connectorName = options.connector.name;
|
|
201
|
+
const db = await useDb(options);
|
|
202
|
+
const tableName = options.tables.passwordResetTokens;
|
|
203
|
+
console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
|
|
204
|
+
if (connectorName === "sqlite") {
|
|
205
|
+
await db.sql`
|
|
206
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
207
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
208
|
+
email TEXT NOT NULL,
|
|
209
|
+
token TEXT NOT NULL UNIQUE,
|
|
210
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
211
|
+
)
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
214
|
+
if (connectorName === "mysql") {
|
|
215
|
+
await db.sql`
|
|
216
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
217
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
218
|
+
email VARCHAR(255) NOT NULL,
|
|
219
|
+
token VARCHAR(255) NOT NULL UNIQUE,
|
|
220
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
221
|
+
)
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
if (connectorName === "postgresql") {
|
|
225
|
+
await db.sql`
|
|
226
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
227
|
+
id SERIAL PRIMARY KEY,
|
|
228
|
+
email VARCHAR(255) NOT NULL,
|
|
229
|
+
token VARCHAR(255) NOT NULL UNIQUE,
|
|
230
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
231
|
+
)
|
|
232
|
+
`;
|
|
233
|
+
}
|
|
234
|
+
await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_email ON {${tableName}} (email)`;
|
|
235
|
+
await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_token ON {${tableName}} (token)`;
|
|
236
|
+
console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Fields: id, email, token, created_at \u2705`);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const createMigrationsTable = async (options) => {
|
|
240
|
+
const connectorName = options.connector.name;
|
|
241
|
+
const db = await useDb(options);
|
|
242
|
+
const tableName = "migrations";
|
|
243
|
+
console.log(`[DB:Create Migrations ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
|
|
244
|
+
if (connectorName === "sqlite") {
|
|
245
|
+
await db.sql`
|
|
246
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
247
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
248
|
+
name TEXT NOT NULL UNIQUE,
|
|
249
|
+
executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
250
|
+
)
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
if (connectorName === "mysql") {
|
|
254
|
+
await db.sql`
|
|
255
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
256
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
257
|
+
name VARCHAR(255) NOT NULL UNIQUE,
|
|
258
|
+
executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
259
|
+
)
|
|
260
|
+
`;
|
|
261
|
+
}
|
|
262
|
+
if (connectorName === "postgresql") {
|
|
263
|
+
await db.sql`
|
|
264
|
+
CREATE TABLE IF NOT EXISTS {${tableName}} (
|
|
265
|
+
id SERIAL PRIMARY KEY,
|
|
266
|
+
name VARCHAR(255) NOT NULL UNIQUE,
|
|
267
|
+
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
268
|
+
)
|
|
269
|
+
`;
|
|
270
|
+
}
|
|
271
|
+
console.log(`[DB:Create Migrations ${connectorName} Table] successfull \u2705`);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const migrations = [
|
|
275
|
+
{
|
|
276
|
+
name: "create_migrations_table",
|
|
277
|
+
run: createMigrationsTable
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: "create_users_table",
|
|
281
|
+
run: createUsersTable
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: "create_personal_access_tokens_table",
|
|
285
|
+
run: createPersonalAccessTokensTable
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "create_password_reset_tokens_table",
|
|
289
|
+
run: createPasswordResetTokensTable
|
|
290
|
+
}
|
|
291
|
+
];
|
|
292
|
+
const getAppliedMigrations = async (options) => {
|
|
293
|
+
const db = await useDb(options);
|
|
294
|
+
try {
|
|
295
|
+
const result = await db.sql`SELECT name FROM migrations ORDER BY id`;
|
|
296
|
+
return result.rows.map((row) => row.name);
|
|
297
|
+
} catch {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const markMigrationAsApplied = async (options, migrationName) => {
|
|
302
|
+
const db = await useDb(options);
|
|
303
|
+
await db.sql`INSERT INTO migrations (name) VALUES (${migrationName})`;
|
|
304
|
+
};
|
|
305
|
+
const runMigrations = async (options) => {
|
|
306
|
+
console.log("[Nuxt Users] Starting migration system...");
|
|
307
|
+
await createMigrationsTable(options);
|
|
308
|
+
const appliedMigrations = await getAppliedMigrations(options);
|
|
309
|
+
console.log(`[Nuxt Users] Applied migrations: ${appliedMigrations.join(", ")}`);
|
|
310
|
+
const pendingMigrations = migrations.filter((migration) => !appliedMigrations.includes(migration.name));
|
|
311
|
+
if (pendingMigrations.length === 0) {
|
|
312
|
+
console.log("[Nuxt Users] No pending migrations to run.");
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
console.log(`[Nuxt Users] Found ${pendingMigrations.length} pending migrations:`);
|
|
316
|
+
pendingMigrations.forEach((migration) => {
|
|
317
|
+
console.log(` - ${migration.name}`);
|
|
318
|
+
});
|
|
319
|
+
for (const migration of pendingMigrations) {
|
|
320
|
+
console.log(`[Nuxt Users] Running migration: ${migration.name}`);
|
|
321
|
+
try {
|
|
322
|
+
await migration.run(options);
|
|
323
|
+
await markMigrationAsApplied(options, migration.name);
|
|
324
|
+
console.log(`[Nuxt Users] \u2713 Migration ${migration.name} successfull \u2705`);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error(`[Nuxt Users] \u2717 Migration ${migration.name} failed:`, error);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
console.log("[Nuxt Users] All migrations successfull \u2705");
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
export { createUser as a, updateUserPassword as b, checkTableExists as c, createUsersTable as d, createPersonalAccessTokensTable as e, findUserByEmail as f, createPasswordResetTokensTable as g, createMigrationsTable as h, runMigrations as r, useDb as u };
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as db0 from 'db0';
|
|
2
|
+
import { M as ModuleOptions, U as User } from './shared/nuxt-users.Dtq4WcpY.mjs';
|
|
3
|
+
|
|
4
|
+
declare const useDb: (options: ModuleOptions) => Promise<db0.Database<db0.Connector<Database.Database>>>;
|
|
5
|
+
declare const checkTableExists: (options: ModuleOptions, tableName: string) => Promise<boolean>;
|
|
6
|
+
|
|
7
|
+
interface CreateUserParams {
|
|
8
|
+
email: string;
|
|
9
|
+
name: string;
|
|
10
|
+
password: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new user in the database.
|
|
14
|
+
* Hashes the password before storing.
|
|
15
|
+
*/
|
|
16
|
+
declare const createUser: (userData: CreateUserParams, options: ModuleOptions) => Promise<Omit<User, "password">>;
|
|
17
|
+
/**
|
|
18
|
+
* Finds a user by their email address.
|
|
19
|
+
*/
|
|
20
|
+
declare const findUserByEmail: (email: string, options: ModuleOptions) => Promise<User | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Updates a user's password.
|
|
23
|
+
* Hashes the new password before storing.
|
|
24
|
+
*/
|
|
25
|
+
declare const updateUserPassword: (email: string, newPassword: string, options: ModuleOptions) => Promise<void>;
|
|
26
|
+
|
|
27
|
+
declare const createUsersTable: (options: ModuleOptions) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
declare const createPersonalAccessTokensTable: (options: ModuleOptions) => Promise<void>;
|
|
30
|
+
|
|
31
|
+
declare const createPasswordResetTokensTable: (options: ModuleOptions) => Promise<void>;
|
|
32
|
+
|
|
33
|
+
declare const createMigrationsTable: (options: ModuleOptions) => Promise<void>;
|
|
34
|
+
|
|
35
|
+
declare const runMigrations: (options: ModuleOptions) => Promise<void>;
|
|
36
|
+
|
|
37
|
+
export { checkTableExists, createMigrationsTable, createPasswordResetTokensTable, createPersonalAccessTokensTable, createUser, createUsersTable, findUserByEmail, runMigrations, updateUserPassword, useDb };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as db0 from 'db0';
|
|
2
|
+
import { M as ModuleOptions, U as User } from './shared/nuxt-users.Dtq4WcpY.js';
|
|
3
|
+
|
|
4
|
+
declare const useDb: (options: ModuleOptions) => Promise<db0.Database<db0.Connector<Database.Database>>>;
|
|
5
|
+
declare const checkTableExists: (options: ModuleOptions, tableName: string) => Promise<boolean>;
|
|
6
|
+
|
|
7
|
+
interface CreateUserParams {
|
|
8
|
+
email: string;
|
|
9
|
+
name: string;
|
|
10
|
+
password: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new user in the database.
|
|
14
|
+
* Hashes the password before storing.
|
|
15
|
+
*/
|
|
16
|
+
declare const createUser: (userData: CreateUserParams, options: ModuleOptions) => Promise<Omit<User, "password">>;
|
|
17
|
+
/**
|
|
18
|
+
* Finds a user by their email address.
|
|
19
|
+
*/
|
|
20
|
+
declare const findUserByEmail: (email: string, options: ModuleOptions) => Promise<User | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Updates a user's password.
|
|
23
|
+
* Hashes the new password before storing.
|
|
24
|
+
*/
|
|
25
|
+
declare const updateUserPassword: (email: string, newPassword: string, options: ModuleOptions) => Promise<void>;
|
|
26
|
+
|
|
27
|
+
declare const createUsersTable: (options: ModuleOptions) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
declare const createPersonalAccessTokensTable: (options: ModuleOptions) => Promise<void>;
|
|
30
|
+
|
|
31
|
+
declare const createPasswordResetTokensTable: (options: ModuleOptions) => Promise<void>;
|
|
32
|
+
|
|
33
|
+
declare const createMigrationsTable: (options: ModuleOptions) => Promise<void>;
|
|
34
|
+
|
|
35
|
+
declare const runMigrations: (options: ModuleOptions) => Promise<void>;
|
|
36
|
+
|
|
37
|
+
export { checkTableExists, createMigrationsTable, createPasswordResetTokensTable, createPersonalAccessTokensTable, createUser, createUsersTable, findUserByEmail, runMigrations, updateUserPassword, useDb };
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { c as checkTableExists, h as createMigrationsTable, g as createPasswordResetTokensTable, e as createPersonalAccessTokensTable, a as createUser, d as createUsersTable, f as findUserByEmail, r as runMigrations, b as updateUserPassword, u as useDb } from './shared/nuxt-users.eSQUrS6l.mjs';
|
|
2
|
+
import 'bcrypt';
|
|
3
|
+
import 'db0';
|
package/package.json
CHANGED
|
@@ -1,56 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-users",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Nuxt
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.5",
|
|
4
|
+
"description": "A comprehensive user management module for Nuxt 3 applications with authentication, database support, and CLI tools",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nuxt",
|
|
7
|
+
"nuxt3",
|
|
8
|
+
"nuxt-module",
|
|
9
|
+
"users",
|
|
10
|
+
"authentication",
|
|
11
|
+
"auth",
|
|
12
|
+
"user-management",
|
|
13
|
+
"sqlite",
|
|
14
|
+
"mysql",
|
|
15
|
+
"postgresql",
|
|
16
|
+
"bcrypt",
|
|
17
|
+
"password-reset",
|
|
18
|
+
"personal-access-tokens",
|
|
19
|
+
"database",
|
|
20
|
+
"cli"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/rrd108/nuxt-users.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/rrd108/nuxt-users/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://nuxt-users.webmania.cc",
|
|
30
|
+
"author": {
|
|
31
|
+
"name": "rrd108",
|
|
32
|
+
"url": "https://github.com/rrd108"
|
|
33
|
+
},
|
|
6
34
|
"license": "MIT",
|
|
7
35
|
"type": "module",
|
|
8
36
|
"exports": {
|
|
9
37
|
".": {
|
|
10
38
|
"types": "./dist/types.d.mts",
|
|
11
39
|
"import": "./dist/module.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./utils": {
|
|
42
|
+
"types": "./dist/utils.d.mts",
|
|
43
|
+
"import": "./dist/utils.mjs"
|
|
12
44
|
}
|
|
13
45
|
},
|
|
14
46
|
"main": "./dist/module.mjs",
|
|
15
|
-
"
|
|
16
|
-
"*": {
|
|
17
|
-
".": [
|
|
18
|
-
"./dist/types.d.mts"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
},
|
|
47
|
+
"types": "./dist/types.d.mts",
|
|
22
48
|
"files": [
|
|
23
49
|
"dist"
|
|
24
50
|
],
|
|
25
51
|
"bin": {
|
|
26
52
|
"nuxt-users": "./dist/cli.mjs"
|
|
27
53
|
},
|
|
28
|
-
"unbuild": {
|
|
29
|
-
"entries": [
|
|
30
|
-
"./src/module",
|
|
31
|
-
{
|
|
32
|
-
"builder": "rollup",
|
|
33
|
-
"input": "./src/cli/main",
|
|
34
|
-
"name": "cli",
|
|
35
|
-
"ext": "mjs"
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"declaration": true,
|
|
39
|
-
"clean": true,
|
|
40
|
-
"failOnWarn": false
|
|
41
|
-
},
|
|
42
54
|
"scripts": {
|
|
43
55
|
"prepack": "nuxt-module-build build",
|
|
44
56
|
"postinstall": "node -e \"try { require('fs').chmodSync('./dist/cli.mjs', '755') } catch(e) {}\"",
|
|
45
|
-
"predev": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for
|
|
57
|
+
"predev": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for development' && exit 1)",
|
|
46
58
|
"dev": "yarn dev:prepare && nuxi dev playground",
|
|
47
59
|
"dev:build": "nuxi build playground",
|
|
48
60
|
"dev:prepare": "yarn nuxt-module-build build --stub && yarn nuxt-module-build prepare && nuxi prepare playground",
|
|
61
|
+
"build": "node scripts/replace-version.js && nuxt-module-build build",
|
|
49
62
|
"prerelease": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
|
|
50
|
-
"release": "yarn lint && yarn test && yarn
|
|
63
|
+
"release": "yarn lint && yarn test && yarn build && changelogen --release && yarn publish && git push --follow-tags",
|
|
51
64
|
"lint": "eslint .",
|
|
52
65
|
"lint:fix": "eslint . --fix",
|
|
53
|
-
"pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for
|
|
66
|
+
"pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for testing' && exit 1)",
|
|
54
67
|
"test": "yarn test:types && yarn test:sqlite && yarn test:mysql && yarn test:postgresql",
|
|
55
68
|
"test:watch": "vitest watch",
|
|
56
69
|
"test:sqlite": "./scripts/test-sqlite.sh",
|
|
@@ -71,25 +84,28 @@
|
|
|
71
84
|
},
|
|
72
85
|
"dependencies": {
|
|
73
86
|
"bcrypt": "^6.0.0",
|
|
74
|
-
"better-sqlite3": "^12.2.0",
|
|
75
87
|
"citty": "^0.1.6",
|
|
76
88
|
"defu": "^6.1.4",
|
|
89
|
+
"nodemailer": "^7.0.5"
|
|
90
|
+
},
|
|
91
|
+
"optionalDependencies": {
|
|
92
|
+
"better-sqlite3": "^12.2.0",
|
|
77
93
|
"mysql2": "^3.14.2",
|
|
78
|
-
"nodemailer": "^7.0.5",
|
|
79
94
|
"pg": "^8.16.3"
|
|
80
95
|
},
|
|
81
96
|
"peerDependencies": {
|
|
82
|
-
"@nuxt/kit": "^3.17.6"
|
|
97
|
+
"@nuxt/kit": "^3.17.6",
|
|
98
|
+
"bcrypt": "^6.0.0",
|
|
99
|
+
"nodemailer": "^7.0.5"
|
|
83
100
|
},
|
|
84
101
|
"devDependencies": {
|
|
85
|
-
"@formkit/nuxt": "^1.6.9",
|
|
86
102
|
"@nuxt/devtools": "^2.6.2",
|
|
87
103
|
"@nuxt/eslint-config": "^1.5.2",
|
|
88
104
|
"@nuxt/kit": "^3.17.6",
|
|
89
105
|
"@nuxt/module-builder": "^1.0.1",
|
|
90
106
|
"@nuxt/schema": "^3.17.6",
|
|
91
107
|
"@nuxt/test-utils": "^3.19.2",
|
|
92
|
-
"@types/bcrypt": "^
|
|
108
|
+
"@types/bcrypt": "^6.0.0",
|
|
93
109
|
"@types/node": "latest",
|
|
94
110
|
"@types/nodemailer": "^6.4.17",
|
|
95
111
|
"@types/pg": "^8.15.4",
|
|
@@ -98,7 +114,7 @@
|
|
|
98
114
|
"nuxt": "^3.17.6",
|
|
99
115
|
"tsx": "^4.20.3",
|
|
100
116
|
"typescript": "~5.8.3",
|
|
101
|
-
"unbuild": "^
|
|
117
|
+
"unbuild": "^3.0.0",
|
|
102
118
|
"vitepress": "^1.6.3",
|
|
103
119
|
"vitest": "^3.2.4",
|
|
104
120
|
"vue-tsc": "^3.0.1"
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { resolve, dirname } from 'node:path';
|
|
2
|
-
import { mkdirSync } from 'node:fs';
|
|
3
|
-
import Database from 'better-sqlite3';
|
|
4
|
-
import { B as BoundableStatement } from '../shared/nuxt-users.C9d5M6B1.mjs';
|
|
5
|
-
|
|
6
|
-
function sqliteConnector(opts) {
|
|
7
|
-
let _db;
|
|
8
|
-
const getDB = () => {
|
|
9
|
-
if (_db) {
|
|
10
|
-
return _db;
|
|
11
|
-
}
|
|
12
|
-
if (opts.name === ":memory:") {
|
|
13
|
-
_db = new Database(":memory:");
|
|
14
|
-
return _db;
|
|
15
|
-
}
|
|
16
|
-
const filePath = resolve(
|
|
17
|
-
opts.cwd || ".",
|
|
18
|
-
opts.path || `.data/${opts.name || "db"}.sqlite3`
|
|
19
|
-
);
|
|
20
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
21
|
-
_db = new Database(filePath);
|
|
22
|
-
return _db;
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
name: "sqlite",
|
|
26
|
-
dialect: "sqlite",
|
|
27
|
-
getInstance: () => getDB(),
|
|
28
|
-
exec: (sql) => getDB().exec(sql),
|
|
29
|
-
prepare: (sql) => new StatementWrapper(() => getDB().prepare(sql))
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
class StatementWrapper extends BoundableStatement {
|
|
33
|
-
async all(...params) {
|
|
34
|
-
return this._statement().all(...params);
|
|
35
|
-
}
|
|
36
|
-
async run(...params) {
|
|
37
|
-
const res = this._statement().run(...params);
|
|
38
|
-
return { success: res.changes > 0, ...res };
|
|
39
|
-
}
|
|
40
|
-
async get(...params) {
|
|
41
|
-
return this._statement().get(...params);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { sqliteConnector as default };
|
package/dist/chunks/mysql2.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import mysql from 'mysql2/promise';
|
|
2
|
-
import { B as BoundableStatement } from '../shared/nuxt-users.C9d5M6B1.mjs';
|
|
3
|
-
|
|
4
|
-
function mysqlConnector(opts) {
|
|
5
|
-
let _connection;
|
|
6
|
-
const getConnection = async () => {
|
|
7
|
-
if (_connection) {
|
|
8
|
-
return _connection;
|
|
9
|
-
}
|
|
10
|
-
_connection = await mysql.createConnection({
|
|
11
|
-
...opts
|
|
12
|
-
});
|
|
13
|
-
return _connection;
|
|
14
|
-
};
|
|
15
|
-
const query = (sql, params) => getConnection().then((c) => c.query(sql, params)).then((res) => res[0]);
|
|
16
|
-
return {
|
|
17
|
-
name: "mysql",
|
|
18
|
-
dialect: "mysql",
|
|
19
|
-
getInstance: () => getConnection(),
|
|
20
|
-
exec: (sql) => query(sql),
|
|
21
|
-
prepare: (sql) => new StatementWrapper(sql, query)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
class StatementWrapper extends BoundableStatement {
|
|
25
|
-
#query;
|
|
26
|
-
#sql;
|
|
27
|
-
constructor(sql, query) {
|
|
28
|
-
super();
|
|
29
|
-
this.#sql = sql;
|
|
30
|
-
this.#query = query;
|
|
31
|
-
}
|
|
32
|
-
async all(...params) {
|
|
33
|
-
const res = await this.#query(this.#sql, params);
|
|
34
|
-
return res;
|
|
35
|
-
}
|
|
36
|
-
async run(...params) {
|
|
37
|
-
const res = await this.#query(this.#sql, params);
|
|
38
|
-
return {
|
|
39
|
-
success: true,
|
|
40
|
-
...res
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
async get(...params) {
|
|
44
|
-
const res = await this.#query(this.#sql, params);
|
|
45
|
-
return res[0];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { mysqlConnector as default };
|