nuxt-users 1.1.2 → 1.1.3

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.
Files changed (48) hide show
  1. package/.vscode/settings.json +18 -0
  2. package/CHANGELOG.md +112 -0
  3. package/README.md +0 -2
  4. package/dist/chunks/better-sqlite3.mjs +45 -0
  5. package/dist/chunks/mysql2.mjs +49 -0
  6. package/dist/chunks/postgresql.mjs +58 -0
  7. package/dist/cli.d.mts +1 -0
  8. package/dist/cli.d.ts +1 -0
  9. package/dist/cli.mjs +587 -0
  10. package/dist/module.d.mts +1 -3
  11. package/dist/module.d.ts +55 -0
  12. package/dist/module.json +1 -1
  13. package/dist/module.mjs +11 -81
  14. package/dist/runtime/assets/colors.css +1 -0
  15. package/dist/runtime/components/ForgotPasswordForm.vue +1 -1
  16. package/dist/runtime/components/LoginForm.vue +1 -1
  17. package/dist/runtime/components/ResetPasswordForm.vue +1 -1
  18. package/dist/runtime/plugin.js +13 -3
  19. package/dist/runtime/server/api/login.post.js +1 -1
  20. package/dist/runtime/server/services/password.js +2 -2
  21. package/dist/shared/nuxt-users.C9d5M6B1.mjs +31 -0
  22. package/package.json +28 -12
  23. package/data/default.sqlite3 +0 -0
  24. package/dist/runtime/server/utils/create-migrations-table.d.ts +0 -2
  25. package/dist/runtime/server/utils/create-migrations-table.js +0 -35
  26. package/dist/runtime/server/utils/create-password-reset-tokens-table.d.ts +0 -2
  27. package/dist/runtime/server/utils/create-password-reset-tokens-table.js +0 -40
  28. package/dist/runtime/server/utils/create-personal-access-tokens-table.d.ts +0 -2
  29. package/dist/runtime/server/utils/create-personal-access-tokens-table.js +0 -56
  30. package/dist/runtime/server/utils/create-user.d.ts +0 -1
  31. package/dist/runtime/server/utils/create-user.js +0 -1
  32. package/dist/runtime/server/utils/create-users-table.d.ts +0 -2
  33. package/dist/runtime/server/utils/create-users-table.js +0 -44
  34. package/dist/runtime/server/utils/db.d.ts +0 -8
  35. package/dist/runtime/server/utils/db.js +0 -61
  36. package/dist/runtime/server/utils/migrate.d.ts +0 -4
  37. package/dist/runtime/server/utils/migrate.js +0 -63
  38. package/dist/runtime/server/utils/user.d.ts +0 -21
  39. package/dist/runtime/server/utils/user.js +0 -50
  40. package/src/cli/create-migrations-table.ts +0 -24
  41. package/src/cli/create-password-reset-tokens-table.ts +0 -24
  42. package/src/cli/create-personal-access-tokens-table.ts +0 -24
  43. package/src/cli/create-user.ts +0 -40
  44. package/src/cli/create-users-table.ts +0 -24
  45. package/src/cli/main.ts +0 -28
  46. package/src/cli/migrate.ts +0 -24
  47. package/src/cli/project-info.ts +0 -45
  48. package/src/cli/utils.ts +0 -70
package/dist/cli.mjs ADDED
@@ -0,0 +1,587 @@
1
+ #!/usr/bin/env node
2
+ import { defineCommand, runMain } from 'citty';
3
+ import bcrypt from 'bcrypt';
4
+ import { loadNuxt } from '@nuxt/kit';
5
+
6
+ function sqlTemplate(strings, ...values) {
7
+ if (!isTemplateStringsArray(strings) || !Array.isArray(values)) {
8
+ throw new Error("[db0] invalid template invocation");
9
+ }
10
+ const staticIndexes = [];
11
+ let result = strings[0] || "";
12
+ for (let i = 1; i < strings.length; i++) {
13
+ if (result.endsWith("{") && strings[i].startsWith("}")) {
14
+ result = result.slice(0, -1) + values[i - 1] + strings[i].slice(1);
15
+ staticIndexes.push(i - 1);
16
+ continue;
17
+ }
18
+ result += `?${strings[i] ?? ""}`;
19
+ }
20
+ const dynamicValues = values.filter((_, i) => !staticIndexes.includes(i));
21
+ return [result.trim(), dynamicValues];
22
+ }
23
+ function isTemplateStringsArray(strings) {
24
+ return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
25
+ }
26
+
27
+ const SQL_SELECT_RE = /^select/i;
28
+ const SQL_RETURNING_RE = /[\s]returning[\s]/i;
29
+ const DIALECTS_WITH_RET = /* @__PURE__ */ new Set(["postgresql", "sqlite"]);
30
+ function createDatabase(connector) {
31
+ return {
32
+ get dialect() {
33
+ return connector.dialect;
34
+ },
35
+ getInstance() {
36
+ return connector.getInstance();
37
+ },
38
+ exec: (sql) => {
39
+ return Promise.resolve(connector.exec(sql));
40
+ },
41
+ prepare: (sql) => {
42
+ return connector.prepare(sql);
43
+ },
44
+ sql: async (strings, ...values) => {
45
+ const [sql, params] = sqlTemplate(strings, ...values);
46
+ if (SQL_SELECT_RE.test(sql) || // prettier-ignore
47
+ DIALECTS_WITH_RET.has(connector.dialect) && SQL_RETURNING_RE.test(sql)) {
48
+ const rows = await connector.prepare(sql).all(...params);
49
+ return {
50
+ rows,
51
+ success: true
52
+ };
53
+ } else {
54
+ const res = await connector.prepare(sql).run(...params);
55
+ return res;
56
+ }
57
+ }
58
+ };
59
+ }
60
+
61
+ const getConnector = async (name) => {
62
+ switch (name) {
63
+ case "mysql":
64
+ return (await import('./chunks/mysql2.mjs')).default;
65
+ case "postgresql":
66
+ return (await import('./chunks/postgresql.mjs')).default;
67
+ case "sqlite":
68
+ return (await import('./chunks/better-sqlite3.mjs')).default;
69
+ default:
70
+ throw new Error(`Unsupported database connector: ${name}`);
71
+ }
72
+ };
73
+ const useDb = async (options) => {
74
+ const connectorName = options.connector.name;
75
+ const connector = await getConnector(connectorName);
76
+ const connectorOptions = { ...options.connector.options };
77
+ if (connectorName !== "sqlite") {
78
+ delete connectorOptions.path;
79
+ }
80
+ try {
81
+ return createDatabase(connector(connectorOptions));
82
+ } catch (error) {
83
+ console.warn(`[Nuxt Users DB] \u26A0\uFE0F Failed to connect to ${connectorName} database:`, error instanceof Error ? error.message : "Unknown error");
84
+ throw error;
85
+ }
86
+ };
87
+
88
+ const createUser$1 = async (userData, options) => {
89
+ const db = await useDb(options);
90
+ const usersTable = options.tables.users;
91
+ const hashedPassword = await bcrypt.hash(userData.password, 10);
92
+ await db.sql`
93
+ INSERT INTO {${usersTable}} (email, name, password, created_at, updated_at)
94
+ VALUES (${userData.email}, ${userData.name}, ${hashedPassword}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
95
+ `;
96
+ const result = await db.sql`SELECT id, email, name, created_at, updated_at FROM {${usersTable}} WHERE email = ${userData.email}`;
97
+ if (result.rows.length === 0) {
98
+ throw new Error("Failed to retrieve created user.");
99
+ }
100
+ const user = result.rows[0];
101
+ return {
102
+ id: user.id,
103
+ email: user.email,
104
+ name: user.name,
105
+ created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
106
+ updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
107
+ };
108
+ };
109
+
110
+ const createUsersTable$1 = async (options) => {
111
+ const connectorName = options.connector.name;
112
+ const db = await useDb(options);
113
+ const tableName = options.tables.users;
114
+ console.log(`[DB:Create ${connectorName} Users Table] Creating ${tableName}...`);
115
+ if (connectorName === "sqlite") {
116
+ await db.sql`
117
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
118
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
119
+ email TEXT NOT NULL UNIQUE,
120
+ name TEXT NOT NULL,
121
+ password TEXT NOT NULL,
122
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
123
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
124
+ )
125
+ `;
126
+ }
127
+ if (connectorName === "mysql") {
128
+ await db.sql`
129
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
130
+ id INT AUTO_INCREMENT PRIMARY KEY,
131
+ email VARCHAR(255) NOT NULL UNIQUE,
132
+ name VARCHAR(255) NOT NULL,
133
+ password VARCHAR(255) NOT NULL,
134
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
135
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
136
+ )
137
+ `;
138
+ }
139
+ if (connectorName === "postgresql") {
140
+ await db.sql`
141
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
142
+ id SERIAL PRIMARY KEY,
143
+ email VARCHAR(255) NOT NULL UNIQUE,
144
+ name VARCHAR(255) NOT NULL,
145
+ password VARCHAR(255) NOT NULL,
146
+ created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
147
+ updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
148
+ )
149
+ `;
150
+ }
151
+ console.log(`[DB:Create ${connectorName} Users Table] Fields: id, email, name, password, created_at, updated_at \u2705`);
152
+ };
153
+
154
+ const createPersonalAccessTokensTable$1 = async (options) => {
155
+ const connectorName = options.connector.name;
156
+ const db = await useDb(options);
157
+ const tableName = options.tables.personalAccessTokens;
158
+ console.log(`[DB:Create Personal Access Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
159
+ if (connectorName === "sqlite") {
160
+ await db.sql`
161
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
162
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
163
+ tokenable_type TEXT NOT NULL,
164
+ tokenable_id INTEGER NOT NULL,
165
+ name TEXT NOT NULL,
166
+ token TEXT NOT NULL UNIQUE,
167
+ abilities TEXT,
168
+ last_used_at DATETIME,
169
+ expires_at DATETIME,
170
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
171
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
172
+ )
173
+ `;
174
+ }
175
+ if (connectorName === "mysql") {
176
+ await db.sql`
177
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
178
+ id INT AUTO_INCREMENT PRIMARY KEY,
179
+ tokenable_type VARCHAR(255) NOT NULL,
180
+ tokenable_id INT NOT NULL,
181
+ name VARCHAR(255) NOT NULL,
182
+ token VARCHAR(255) NOT NULL UNIQUE,
183
+ abilities TEXT,
184
+ last_used_at DATETIME,
185
+ expires_at DATETIME,
186
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
187
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
188
+ )
189
+ `;
190
+ }
191
+ if (connectorName === "postgresql") {
192
+ await db.sql`
193
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
194
+ id SERIAL PRIMARY KEY,
195
+ tokenable_type VARCHAR(255) NOT NULL,
196
+ tokenable_id INT NOT NULL,
197
+ name VARCHAR(255) NOT NULL,
198
+ token VARCHAR(255) NOT NULL UNIQUE,
199
+ abilities TEXT,
200
+ last_used_at TIMESTAMPTZ,
201
+ expires_at TIMESTAMPTZ,
202
+ created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
203
+ updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
204
+ )
205
+ `;
206
+ }
207
+ 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`);
208
+ };
209
+
210
+ const createPasswordResetTokensTable$1 = async (options) => {
211
+ const connectorName = options.connector.name;
212
+ const db = await useDb(options);
213
+ const tableName = options.tables.passwordResetTokens;
214
+ console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
215
+ if (connectorName === "sqlite") {
216
+ await db.sql`
217
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
218
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
219
+ email TEXT NOT NULL,
220
+ token TEXT NOT NULL UNIQUE,
221
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
222
+ )
223
+ `;
224
+ }
225
+ if (connectorName === "mysql") {
226
+ await db.sql`
227
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
228
+ id INT AUTO_INCREMENT PRIMARY KEY,
229
+ email VARCHAR(255) NOT NULL,
230
+ token VARCHAR(255) NOT NULL UNIQUE,
231
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
232
+ )
233
+ `;
234
+ }
235
+ if (connectorName === "postgresql") {
236
+ await db.sql`
237
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
238
+ id SERIAL PRIMARY KEY,
239
+ email VARCHAR(255) NOT NULL,
240
+ token VARCHAR(255) NOT NULL UNIQUE,
241
+ created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
242
+ )
243
+ `;
244
+ }
245
+ await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_email ON {${tableName}} (email)`;
246
+ await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_token ON {${tableName}} (token)`;
247
+ console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Fields: id, email, token, created_at \u2705`);
248
+ };
249
+
250
+ const createMigrationsTable$1 = async (options) => {
251
+ const connectorName = options.connector.name;
252
+ const db = await useDb(options);
253
+ const tableName = "migrations";
254
+ console.log(`[DB:Create Migrations ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
255
+ if (connectorName === "sqlite") {
256
+ await db.sql`
257
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
258
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
259
+ name TEXT NOT NULL UNIQUE,
260
+ executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
261
+ )
262
+ `;
263
+ }
264
+ if (connectorName === "mysql") {
265
+ await db.sql`
266
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
267
+ id INT AUTO_INCREMENT PRIMARY KEY,
268
+ name VARCHAR(255) NOT NULL UNIQUE,
269
+ executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
270
+ )
271
+ `;
272
+ }
273
+ if (connectorName === "postgresql") {
274
+ await db.sql`
275
+ CREATE TABLE IF NOT EXISTS {${tableName}} (
276
+ id SERIAL PRIMARY KEY,
277
+ name VARCHAR(255) NOT NULL UNIQUE,
278
+ executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
279
+ )
280
+ `;
281
+ }
282
+ console.log(`[DB:Create Migrations ${connectorName} Table] successfull \u2705`);
283
+ };
284
+
285
+ const migrations = [
286
+ {
287
+ name: "create_migrations_table",
288
+ run: createMigrationsTable$1
289
+ },
290
+ {
291
+ name: "create_users_table",
292
+ run: createUsersTable$1
293
+ },
294
+ {
295
+ name: "create_personal_access_tokens_table",
296
+ run: createPersonalAccessTokensTable$1
297
+ },
298
+ {
299
+ name: "create_password_reset_tokens_table",
300
+ run: createPasswordResetTokensTable$1
301
+ }
302
+ ];
303
+ const getAppliedMigrations = async (options) => {
304
+ const db = await useDb(options);
305
+ try {
306
+ const result = await db.sql`SELECT name FROM migrations ORDER BY id`;
307
+ return result.rows.map((row) => row.name);
308
+ } catch {
309
+ return [];
310
+ }
311
+ };
312
+ const markMigrationAsApplied = async (options, migrationName) => {
313
+ const db = await useDb(options);
314
+ await db.sql`INSERT INTO migrations (name) VALUES (${migrationName})`;
315
+ };
316
+ const runMigrations = async (options) => {
317
+ console.log("[Nuxt Users] Starting migration system...");
318
+ await createMigrationsTable$1(options);
319
+ const appliedMigrations = await getAppliedMigrations(options);
320
+ console.log(`[Nuxt Users] Applied migrations: ${appliedMigrations.join(", ")}`);
321
+ const pendingMigrations = migrations.filter((migration) => !appliedMigrations.includes(migration.name));
322
+ if (pendingMigrations.length === 0) {
323
+ console.log("[Nuxt Users] No pending migrations to run.");
324
+ return;
325
+ }
326
+ console.log(`[Nuxt Users] Found ${pendingMigrations.length} pending migrations:`);
327
+ pendingMigrations.forEach((migration) => {
328
+ console.log(` - ${migration.name}`);
329
+ });
330
+ for (const migration of pendingMigrations) {
331
+ console.log(`[Nuxt Users] Running migration: ${migration.name}`);
332
+ try {
333
+ await migration.run(options);
334
+ await markMigrationAsApplied(options, migration.name);
335
+ console.log(`[Nuxt Users] \u2713 Migration ${migration.name} successfull \u2705`);
336
+ } catch (error) {
337
+ console.error(`[Nuxt Users] \u2717 Migration ${migration.name} failed:`, error);
338
+ throw error;
339
+ }
340
+ }
341
+ console.log("[Nuxt Users] All migrations successfull \u2705");
342
+ };
343
+
344
+ const defaultOptions = {
345
+ connector: {
346
+ name: "sqlite",
347
+ options: {
348
+ path: "./data/users.sqlite3"
349
+ }
350
+ },
351
+ tables: {
352
+ migrations: "migrations",
353
+ users: "users",
354
+ personalAccessTokens: "personal_access_tokens",
355
+ passwordResetTokens: "password_reset_tokens"
356
+ },
357
+ mailer: {
358
+ host: "smtp.ethereal.email",
359
+ port: 587,
360
+ secure: false,
361
+ auth: {
362
+ user: "user@ethereal.email",
363
+ pass: "password"
364
+ },
365
+ defaults: {
366
+ from: '"Nuxt Users Module" <noreply@example.com>'
367
+ }
368
+ },
369
+ passwordResetBaseUrl: "http://localhost:3000"
370
+ };
371
+ const getOptionsFromEnv = () => {
372
+ const connectorName = process.env.DB_CONNECTOR || "sqlite";
373
+ let connectorOptions;
374
+ switch (connectorName) {
375
+ case "sqlite":
376
+ connectorOptions = {
377
+ path: process.env.DB_PATH || "./data/default.sqlite3"
378
+ };
379
+ break;
380
+ case "mysql":
381
+ connectorOptions = {
382
+ host: process.env.DB_HOST || "localhost",
383
+ port: Number.parseInt(process.env.DB_PORT || "3306"),
384
+ user: process.env.DB_USER || "root",
385
+ password: process.env.DB_PASSWORD || "",
386
+ database: process.env.DB_NAME || "nuxt_users"
387
+ };
388
+ break;
389
+ case "postgresql":
390
+ connectorOptions = {
391
+ host: process.env.DB_HOST || "localhost",
392
+ port: Number.parseInt(process.env.DB_PORT || "5432"),
393
+ user: process.env.DB_USER || "postgres",
394
+ password: process.env.DB_PASSWORD || "",
395
+ database: process.env.DB_NAME || "nuxt_users"
396
+ };
397
+ break;
398
+ default:
399
+ throw new Error(`Unsupported database connector: ${connectorName}`);
400
+ }
401
+ return {
402
+ ...defaultOptions,
403
+ connector: {
404
+ name: connectorName,
405
+ options: connectorOptions
406
+ }
407
+ };
408
+ };
409
+
410
+ const migrate = defineCommand({
411
+ meta: {
412
+ name: "migrate",
413
+ description: "Run database migrations for the Nuxt Users module"
414
+ },
415
+ async run() {
416
+ console.log("[Nuxt Users] Starting migration system...");
417
+ const options = getOptionsFromEnv();
418
+ try {
419
+ await runMigrations(options);
420
+ console.log("[Nuxt Users] Migration completed successfully!");
421
+ } catch (error) {
422
+ console.error("[Nuxt Users] Migration failed:", error);
423
+ process.exit(1);
424
+ }
425
+ }
426
+ });
427
+
428
+ const createUser = defineCommand({
429
+ meta: {
430
+ name: "create-user",
431
+ description: "Create a new user in the database"
432
+ },
433
+ args: {
434
+ email: {
435
+ type: "string",
436
+ description: "User email address",
437
+ required: true
438
+ },
439
+ name: {
440
+ type: "string",
441
+ description: "User full name",
442
+ required: true
443
+ },
444
+ password: {
445
+ type: "string",
446
+ description: "User password",
447
+ required: true
448
+ }
449
+ },
450
+ async run({ args }) {
451
+ const { email, name, password } = args;
452
+ const options = getOptionsFromEnv();
453
+ try {
454
+ const user = await createUser$1({ email, name, password }, options);
455
+ console.log(`[DB:Create User] User created successfully: ${user.email}`);
456
+ } catch (error) {
457
+ console.error("[DB:Create User] Error:", error);
458
+ process.exit(1);
459
+ }
460
+ }
461
+ });
462
+
463
+ const createUsersTable = defineCommand({
464
+ meta: {
465
+ name: "create-users-table",
466
+ description: "Create the users table in the database"
467
+ },
468
+ async run() {
469
+ console.log("[Nuxt Users] Creating users table...");
470
+ const options = getOptionsFromEnv();
471
+ try {
472
+ await createUsersTable$1(options);
473
+ console.log("[Nuxt Users] Users table created successfully!");
474
+ } catch (error) {
475
+ console.error("[DB:Create Users Table] Error:", error);
476
+ process.exit(1);
477
+ }
478
+ }
479
+ });
480
+
481
+ const createPersonalAccessTokensTable = defineCommand({
482
+ meta: {
483
+ name: "create-personal-access-tokens-table",
484
+ description: "Create the personal access tokens table in the database"
485
+ },
486
+ async run() {
487
+ console.log("[Nuxt Users] Creating personal access tokens table...");
488
+ const options = getOptionsFromEnv();
489
+ try {
490
+ await createPersonalAccessTokensTable$1(options);
491
+ console.log("[Nuxt Users] Personal access tokens table created successfully!");
492
+ } catch (error) {
493
+ console.error("[DB:Create Personal Access Tokens Table] Error:", error);
494
+ process.exit(1);
495
+ }
496
+ }
497
+ });
498
+
499
+ const createPasswordResetTokensTable = defineCommand({
500
+ meta: {
501
+ name: "create-password-reset-tokens-table",
502
+ description: "Create the password reset tokens table in the database"
503
+ },
504
+ async run() {
505
+ console.log("[Nuxt Users] Creating password reset tokens table...");
506
+ const options = getOptionsFromEnv();
507
+ try {
508
+ await createPasswordResetTokensTable$1(options);
509
+ console.log("[Nuxt Users] Password reset tokens table created successfully!");
510
+ } catch (error) {
511
+ console.error("[DB:Create Password Reset Tokens Table] Error:", error);
512
+ process.exit(1);
513
+ }
514
+ }
515
+ });
516
+
517
+ const createMigrationsTable = defineCommand({
518
+ meta: {
519
+ name: "create-migrations-table",
520
+ description: "Create the migrations table in the database"
521
+ },
522
+ async run() {
523
+ console.log("[Nuxt Users] Creating migrations table...");
524
+ const options = getOptionsFromEnv();
525
+ try {
526
+ await createMigrationsTable$1(options);
527
+ console.log("[Nuxt Users] Migrations table created successfully!");
528
+ } catch (error) {
529
+ console.error("[DB:Create Migrations Table] Error:", error);
530
+ process.exit(1);
531
+ }
532
+ }
533
+ });
534
+
535
+ const projectInfo = defineCommand({
536
+ meta: {
537
+ name: "project-info",
538
+ description: "Get information about the Nuxt project and module configuration"
539
+ },
540
+ async run() {
541
+ try {
542
+ console.log("[Nuxt Users] Loading Nuxt project...");
543
+ const nuxt = await loadNuxt({ cwd: process.cwd() });
544
+ console.log("\u2705 Nuxt project loaded successfully!");
545
+ console.log("\u{1F4C1} Source directory:", nuxt.options.srcDir);
546
+ console.log("\u{1F310} Base URL:", nuxt.options.app?.baseURL || "/");
547
+ const nuxtUsersConfig = nuxt.options.runtimeConfig?.nuxtUsers;
548
+ if (nuxtUsersConfig) {
549
+ console.log("\u{1F527} Nuxt Users module configuration:");
550
+ console.log(" Database connector:", nuxtUsersConfig.connector?.name);
551
+ console.log(" Users table:", nuxtUsersConfig.tables?.users);
552
+ console.log(" Personal access tokens table:", nuxtUsersConfig.tables?.personalAccessTokens);
553
+ console.log(" Password reset tokens table:", nuxtUsersConfig.tables?.passwordResetTokens);
554
+ } else {
555
+ console.log("\u26A0\uFE0F Nuxt Users module not configured in runtime config");
556
+ }
557
+ const publicConfig = nuxt.options.runtimeConfig?.public?.nuxtUsers;
558
+ if (publicConfig) {
559
+ console.log("\u{1F30D} Public runtime config:");
560
+ console.log(" Users table exists:", publicConfig.tables?.users);
561
+ console.log(" Personal access tokens table exists:", publicConfig.tables?.personalAccessTokens);
562
+ console.log(" Password reset tokens table exists:", publicConfig.tables?.passwordResetTokens);
563
+ }
564
+ } catch (error) {
565
+ console.error("\u274C Could not load Nuxt project:", error);
566
+ process.exit(1);
567
+ }
568
+ }
569
+ });
570
+
571
+ const main = defineCommand({
572
+ meta: {
573
+ name: "nuxt-users",
574
+ description: "CLI for Nuxt Users Module - Manage users, migrations, and database operations",
575
+ version: "1.1.0"
576
+ },
577
+ subCommands: {
578
+ migrate,
579
+ "create-user": createUser,
580
+ "create-users-table": createUsersTable,
581
+ "create-personal-access-tokens-table": createPersonalAccessTokensTable,
582
+ "create-password-reset-tokens-table": createPasswordResetTokensTable,
583
+ "create-migrations-table": createMigrationsTable,
584
+ "project-info": projectInfo
585
+ }
586
+ });
587
+ runMain(main);
package/dist/module.d.mts CHANGED
@@ -8,9 +8,6 @@ type DatabaseConfig = {
8
8
  user?: string;
9
9
  password?: string;
10
10
  database?: string;
11
- connectTimeout?: number;
12
- acquireTimeout?: number;
13
- connectionTimeoutMillis?: number;
14
11
  };
15
12
  interface ModuleOptions {
16
13
  connector?: {
@@ -18,6 +15,7 @@ interface ModuleOptions {
18
15
  options: DatabaseConfig;
19
16
  };
20
17
  tables: {
18
+ migrations: string;
21
19
  users: string;
22
20
  personalAccessTokens: string;
23
21
  passwordResetTokens: string;
@@ -0,0 +1,55 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ type DatabaseType = 'sqlite' | 'mysql' | 'postgresql';
4
+ type DatabaseConfig = {
5
+ path?: string;
6
+ host?: string;
7
+ port?: number;
8
+ user?: string;
9
+ password?: string;
10
+ database?: string;
11
+ };
12
+ interface ModuleOptions {
13
+ connector?: {
14
+ name: DatabaseType;
15
+ options: DatabaseConfig;
16
+ };
17
+ tables: {
18
+ migrations: string;
19
+ users: string;
20
+ personalAccessTokens: string;
21
+ passwordResetTokens: string;
22
+ };
23
+ /**
24
+ * Mailer configuration options for sending emails (e.g., password resets)
25
+ * Uses nodemailer
26
+ */
27
+ mailer?: MailerOptions;
28
+ /**
29
+ * Base URL for password reset links
30
+ * @default 'http://localhost:3000' // Example, will be set in module defaults
31
+ */
32
+ passwordResetBaseUrl?: string;
33
+ /**
34
+ * Skip database checks during module setup to prevent hanging
35
+ * @default false
36
+ */
37
+ skipDatabaseChecks?: boolean;
38
+ }
39
+ interface MailerOptions {
40
+ host: string;
41
+ port: number;
42
+ secure?: boolean;
43
+ auth: {
44
+ user: string;
45
+ pass: string;
46
+ };
47
+ defaults?: {
48
+ from: string;
49
+ };
50
+ }
51
+
52
+ declare const defaultOptions: ModuleOptions;
53
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
54
+
55
+ export { _default as default, defaultOptions };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
3
  "configKey": "nuxtUsers",
4
- "version": "1.1.2",
4
+ "version": "1.1.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "2.0.0"