nuxt-users 1.1.1 → 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 (46) hide show
  1. package/.vscode/settings.json +18 -0
  2. package/CHANGELOG.md +112 -0
  3. package/dist/chunks/better-sqlite3.mjs +45 -0
  4. package/dist/chunks/mysql2.mjs +49 -0
  5. package/dist/chunks/postgresql.mjs +58 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.d.ts +1 -0
  8. package/dist/cli.mjs +587 -0
  9. package/dist/module.d.mts +6 -0
  10. package/dist/module.d.ts +55 -0
  11. package/dist/module.json +1 -1
  12. package/dist/module.mjs +12 -40
  13. package/dist/runtime/assets/colors.css +1 -0
  14. package/dist/runtime/components/ForgotPasswordForm.vue +1 -1
  15. package/dist/runtime/components/LoginForm.vue +1 -1
  16. package/dist/runtime/components/ResetPasswordForm.vue +1 -1
  17. package/dist/runtime/plugin.js +13 -3
  18. package/dist/runtime/server/api/login.post.js +1 -1
  19. package/dist/runtime/server/services/password.js +2 -2
  20. package/dist/shared/nuxt-users.C9d5M6B1.mjs +31 -0
  21. package/package.json +28 -10
  22. package/dist/runtime/server/utils/create-migrations-table.d.ts +0 -2
  23. package/dist/runtime/server/utils/create-migrations-table.js +0 -35
  24. package/dist/runtime/server/utils/create-password-reset-tokens-table.d.ts +0 -2
  25. package/dist/runtime/server/utils/create-password-reset-tokens-table.js +0 -40
  26. package/dist/runtime/server/utils/create-personal-access-tokens-table.d.ts +0 -2
  27. package/dist/runtime/server/utils/create-personal-access-tokens-table.js +0 -56
  28. package/dist/runtime/server/utils/create-user.d.ts +0 -1
  29. package/dist/runtime/server/utils/create-user.js +0 -1
  30. package/dist/runtime/server/utils/create-users-table.d.ts +0 -2
  31. package/dist/runtime/server/utils/create-users-table.js +0 -44
  32. package/dist/runtime/server/utils/db.d.ts +0 -8
  33. package/dist/runtime/server/utils/db.js +0 -49
  34. package/dist/runtime/server/utils/migrate.d.ts +0 -4
  35. package/dist/runtime/server/utils/migrate.js +0 -63
  36. package/dist/runtime/server/utils/user.d.ts +0 -21
  37. package/dist/runtime/server/utils/user.js +0 -50
  38. package/src/cli/create-migrations-table.ts +0 -24
  39. package/src/cli/create-password-reset-tokens-table.ts +0 -24
  40. package/src/cli/create-personal-access-tokens-table.ts +0 -24
  41. package/src/cli/create-user.ts +0 -40
  42. package/src/cli/create-users-table.ts +0 -24
  43. package/src/cli/main.ts +0 -28
  44. package/src/cli/migrate.ts +0 -24
  45. package/src/cli/project-info.ts +0 -45
  46. package/src/cli/utils.ts +0 -70
package/dist/module.mjs CHANGED
@@ -1,16 +1,15 @@
1
- import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addComponent } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addComponent } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
- import { checkUsersTableExists, checkPersonalAccessTokensTableExists, checkPasswordResetTokensTableExists, hasAnyUsers } from '../dist/runtime/server/utils/db.js';
4
- import { getAppliedMigrations } from '../dist/runtime/server/utils/migrate.js';
5
3
 
6
4
  const defaultOptions = {
7
5
  connector: {
8
6
  name: "sqlite",
9
7
  options: {
10
- path: "./data/default.sqlite3"
8
+ path: "./data/users.sqlite3"
11
9
  }
12
10
  },
13
11
  tables: {
12
+ migrations: "migrations",
14
13
  users: "users",
15
14
  personalAccessTokens: "personal_access_tokens",
16
15
  passwordResetTokens: "password_reset_tokens"
@@ -29,9 +28,7 @@ const defaultOptions = {
29
28
  defaults: {
30
29
  from: '"Nuxt Users Module" <noreply@example.com>'
31
30
  }
32
- },
33
- passwordResetBaseUrl: "http://localhost:3000"
34
- // Added
31
+ }
35
32
  };
36
33
  const module = defineNuxtModule({
37
34
  meta: {
@@ -42,34 +39,11 @@ const module = defineNuxtModule({
42
39
  defaults: defaultOptions,
43
40
  async setup(options, nuxt) {
44
41
  const resolver = createResolver(import.meta.url);
45
- const appliedMigrations = await getAppliedMigrations(options);
46
- const requiredMigrations = [
47
- "create_migrations_table",
48
- "create_users_table",
49
- "create_personal_access_tokens_table",
50
- "create_password_reset_tokens_table"
51
- ];
52
- const missingMigrations = requiredMigrations.filter((migration) => !appliedMigrations.includes(migration));
53
- if (missingMigrations.length > 0) {
54
- console.warn(`[Nuxt Users DB] \u26A0\uFE0F Missing migrations: ${missingMigrations.join(", ")}`);
55
- console.warn("[Nuxt Users DB] \u26A0\uFE0F Run migrations with: npx nuxt-users-migrate");
56
- }
57
- const hasUsersTable = await checkUsersTableExists(options);
58
- if (!hasUsersTable) {
59
- console.warn("[Nuxt Users DB] \u26A0\uFE0F Users table does not exist, you should run the migration script to create it by running: npx nuxt-users-migrate");
60
- }
61
- const hasPersonalAccessTokensTable = await checkPersonalAccessTokensTableExists(options);
62
- if (!hasPersonalAccessTokensTable) {
63
- console.warn("[Nuxt Users DB] \u26A0\uFE0F Personal access tokens table does not exist, you should run the migration script to create it by running: npx nuxt-users-migrate");
64
- }
65
- const hasPasswordResetTokensTable = await checkPasswordResetTokensTableExists(options);
66
- if (!hasPasswordResetTokensTable) {
67
- console.warn("[Nuxt Users DB] \u26A0\uFE0F Password reset tokens table does not exist, you should run the migration script to create it by running: npx nuxt-users-migrate");
68
- }
69
42
  const runtimeConfigOptions = defu(options, nuxt.options.runtimeConfig.nuxtUsers || {}, defaultOptions);
70
43
  nuxt.options.runtimeConfig.nuxtUsers = {
71
44
  ...runtimeConfigOptions,
72
45
  tables: {
46
+ migrations: options.tables?.migrations || "migrations",
73
47
  users: options.tables?.users || "users",
74
48
  personalAccessTokens: options.tables?.personalAccessTokens || "personal_access_tokens",
75
49
  passwordResetTokens: options.tables?.passwordResetTokens || "password_reset_tokens"
@@ -78,16 +52,13 @@ const module = defineNuxtModule({
78
52
  nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {};
79
53
  nuxt.options.runtimeConfig.public.nuxtUsers = {
80
54
  tables: {
81
- users: hasUsersTable,
82
- personalAccessTokens: hasPersonalAccessTokensTable,
83
- passwordResetTokens: hasPasswordResetTokensTable
84
- // Use stored value
55
+ migrations: options.tables?.migrations,
56
+ users: options.tables?.users,
57
+ personalAccessTokens: options.tables?.personalAccessTokens,
58
+ passwordResetTokens: options.tables?.passwordResetTokens
85
59
  }
86
60
  };
87
- const hasUsers = await hasAnyUsers(options);
88
- if (!hasUsers) {
89
- console.warn('[Nuxt Users DB] \u26A0\uFE0F No users found! Create a default user by running: npx nuxt-users-create-user rrd@example.com "John Doe" mypassword123');
90
- }
61
+ addPlugin(resolver.resolve("./runtime/plugin"));
91
62
  addServerHandler({
92
63
  route: "/api/login",
93
64
  method: "post",
@@ -103,7 +74,6 @@ const module = defineNuxtModule({
103
74
  method: "post",
104
75
  handler: resolver.resolve("./runtime/server/api/auth/reset-password.post")
105
76
  });
106
- addPlugin(resolver.resolve("./runtime/plugin"));
107
77
  addComponent({
108
78
  name: "LoginForm",
109
79
  filePath: resolver.resolve("./runtime/components/LoginForm.vue")
@@ -116,6 +86,8 @@ const module = defineNuxtModule({
116
86
  name: "ResetPasswordForm",
117
87
  filePath: resolver.resolve("./runtime/components/ResetPasswordForm.vue")
118
88
  });
89
+ nuxt.options.css = nuxt.options.css || [];
90
+ nuxt.options.css.push(resolver.resolve("./runtime/assets/colors.css"));
119
91
  }
120
92
  });
121
93
 
@@ -0,0 +1 @@
1
+ :root{--color-primary:#3b82f6;--color-primary-dark:#2563eb;--color-primary-light:#60a5fa;--color-secondary:#059669;--color-secondary-dark:#047857;--color-secondary-light:#10b981;--color-white:#fff;--color-black:#000;--color-gray-50:#f9fafb;--color-gray-100:#f3f4f6;--color-gray-200:#e5e7eb;--color-gray-300:#d1d5db;--color-gray-400:#9ca3af;--color-gray-500:#6b7280;--color-gray-600:#4b5563;--color-gray-700:#374151;--color-gray-800:#1f2937;--color-gray-900:#111827;--color-success:#059669;--color-success-light:#f0fdf4;--color-warning:#f59e0b;--color-warning-light:#fef3c7;--color-warning-text:#92400e;--color-error:#dc2626;--color-error-light:#fef2f2;--color-error-border:#fecaca;--color-error-alt:#db5050;--color-border:#e5e7eb;--color-border-light:#d1d5db;--color-border-dark:#ccc;--color-bg-primary:#fff;--color-bg-secondary:#f9fafb;--color-bg-tertiary:#f3f4f6}
@@ -75,5 +75,5 @@ const handleForgotPassword = async (data) => {
75
75
  </template>
76
76
 
77
77
  <style scoped>
78
- .error{color:red}.success{color:green}.form-message{font-size:.9rem;margin-top:1rem}:deep(.formkit-outer){margin-bottom:1rem}:deep(.formkit-label){display:block;font-weight:700;margin-bottom:.25rem}:deep(.formkit-input input[type=email]),:deep(.formkit-input input[type=password]){border:1px solid #ccc;border-radius:4px;box-sizing:border-box;padding:.75rem;width:100%}:deep(.formkit-input input[type=submit]){background-color:#333;border:none;border-radius:4px;color:#fff;cursor:pointer;padding:.75rem 1.5rem}:deep(.formkit-input input[type=submit]:disabled){background-color:#aaa;cursor:not-allowed}:deep(.formkit-messages){list-style:none;margin-top:.25rem;padding:0}:deep(.formkit-message){color:red;font-size:.8rem}
78
+ .error{color:red}.success{color:green}.form-message{font-size:.9rem;margin-top:1em}:deep(.formkit-outer){margin-bottom:1em}:deep(.formkit-label){display:block;font-weight:700;margin-bottom:.25em}:deep(.formkit-input input[type=email]),:deep(.formkit-input input[type=password]){border:1px solid var(--color-border-dark);border-radius:4px;box-sizing:border-box;padding:.75em;width:100%}:deep(.formkit-input input[type=submit]){background-color:var(--color-gray-800);border:none;border-radius:4px;color:#fff;cursor:pointer;padding:.75em 1.5em}:deep(.formkit-input input[type=submit]:disabled){background-color:var(--color-gray-500);cursor:not-allowed}:deep(.formkit-messages){list-style:none;margin-top:.25em;padding:0}:deep(.formkit-message){color:red;font-size:.8rem}
79
79
  </style>
@@ -129,5 +129,5 @@ const handleSubmit = async (formData) => {
129
129
  </template>
130
130
 
131
131
  <style scoped>
132
- .login-form-container{background:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);margin:0 auto;max-width:400px;padding:2rem;width:100%}:deep(.formkit-form){display:flex;flex-direction:column;gap:1.5rem}.login-header{margin-bottom:1rem;text-align:center}.login-title{color:#111827;font-size:1.875rem;font-weight:700;line-height:1.2;margin:0 0 .5rem}.login-subtitle{color:#6b7280;font-size:.875rem;line-height:1.5;margin:0}:deep(.formkit-inner){--fk-border-radius:8px;--fk-border-color:#d1d5db;--fk-border-color-focus:#3b82f6;--fk-bg-color:#f9fafb;--fk-bg-color-focus:#fff;--fk-text-color:#374151;--fk-text-color-placeholder:#9ca3af;--fk-font-size:0.875rem;--fk-padding:0.75rem 1rem;--fk-transition:all 0.2s ease-in-out}:deep(.formkit-inner .formkit-input){background-color:var(--fk-bg-color);border:1px solid var(--fk-border-color);border-radius:var(--fk-border-radius);box-sizing:border-box;color:var(--fk-text-color);font-size:var(--fk-font-size);padding:var(--fk-padding);transition:var(--fk-transition);width:100%}:deep(.formkit-inner .formkit-input:focus){background-color:var(--fk-bg-color-focus);border-color:var(--fk-border-color-focus);box-shadow:0 0 0 3px rgba(59,130,246,.1);outline:none}:deep(.formkit-inner .formkit-label){color:#374151;display:block;font-size:.875rem;font-weight:500;margin-bottom:.5rem}:deep(.formkit-messages){font-size:.75rem;list-style:none;padding:0}:deep(.formkit-message){margin-top:.25rem}:deep(.formkit-message[data-message-type=validation]){color:#db5050}:deep(.formkit-message[data-message-type=error]){color:#dc2626}:deep(.formkit-wrapper:has(input[type=checkbox])){align-items:center;display:flex;gap:.5rem}:deep(.formkit-input[type=checkbox]){margin:0;width:auto}:deep(.formkit-label:has(input[type=checkbox])){color:#374151;font-size:.875rem;margin:0}:deep(button[type=submit]){align-items:center;background-color:#3b82f6;border:1px solid #3b82f6;border-radius:8px;color:#fff;cursor:pointer;display:flex;font-size:.875rem;font-weight:500;gap:.5rem;justify-content:center;min-height:44px;padding:.75rem 1rem;transition:all .2s ease-in-out;width:100%}:deep(button[type=submit]:hover:not(:disabled)){background-color:#2563eb;border-color:#2563eb}:deep(button[type=submit]:disabled){cursor:not-allowed;opacity:.6}.loading-spinner{animation:spin 1s linear infinite;border:2px solid #fff;border-radius:50%;border-top-color:transparent;height:16px;width:16px}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.login-footer{margin-top:1rem;text-align:center}.forgot-password{margin:0}.forgot-link{color:#3b82f6;font-size:.875rem;text-decoration:none;transition:color .2s ease-in-out}.forgot-link:hover{color:#2563eb;text-decoration:underline}.error-message{background-color:#fef2f2;border:1px solid #fecaca;border-radius:8px;color:#dc2626;font-size:.875rem;margin-top:1rem;padding:.75rem 1rem;text-align:center}@media (max-width:480px){.login-form-container{margin:1rem;padding:1.5rem}.login-title{font-size:1.5rem}}
132
+ .login-form-container{background:var(--color-bg-primary);border:1px solid var(--color-border);border-radius:12px;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);margin:0 auto;max-width:400px;padding:2em;width:100%}:deep(.formkit-form){display:flex;flex-direction:column;gap:1.5rem}.login-header{margin-bottom:1em;text-align:center}.login-title{color:var(--color-gray-800);font-size:1.875rem;font-weight:700;line-height:1.2;margin:0 0 .5em}.login-subtitle{color:var(--color-gray-500);font-size:.875rem;line-height:1.5;margin:0}:deep(.formkit-inner){--fk-border-radius:8px;--fk-border-color:var(--color-border-light);--fk-border-color-focus:var(--color-primary);--fk-bg-color:var(--color-bg-secondary);--fk-bg-color-focus:var(--color-bg-primary);--fk-text-color:var(--color-gray-700);--fk-text-color-placeholder:var(--color-gray-400);--fk-font-size:0.875rem;--fk-padding:0.75em 1em;--fk-transition:all 0.2s ease-in-out}:deep(.formkit-inner .formkit-input){background-color:var(--fk-bg-color);border:1px solid var(--fk-border-color);border-radius:var(--fk-border-radius);box-sizing:border-box;color:var(--fk-text-color);font-size:var(--fk-font-size);padding:var(--fk-padding);transition:var(--fk-transition);width:100%}:deep(.formkit-inner .formkit-input:focus){background-color:var(--fk-bg-color-focus);border-color:var(--fk-border-color-focus);box-shadow:0 0 0 3px rgba(59,130,246,.1);outline:none}:deep(.formkit-inner .formkit-label){color:var(--color-gray-700);display:block;font-size:.875rem;font-weight:500;margin-bottom:.5em}:deep(.formkit-messages){font-size:.75rem;list-style:none;padding:0}:deep(.formkit-message){margin-top:.25em}:deep(.formkit-message[data-message-type=validation]){color:var(--color-error-alt)}:deep(.formkit-message[data-message-type=error]){color:var(--color-error)}:deep(.formkit-wrapper:has(input[type=checkbox])){align-items:center;display:flex;gap:.5rem}:deep(.formkit-input[type=checkbox]){margin:0;width:auto}:deep(.formkit-label:has(input[type=checkbox])){color:var(--color-gray-700);font-size:.875rem;margin:0}:deep(button[type=submit]){align-items:center;background-color:var(--color-primary);border:1px solid var(--color-primary);border-radius:8px;color:var(--color-white);cursor:pointer;display:flex;font-size:.875rem;font-weight:500;gap:.5rem;justify-content:center;min-height:44px;padding:.75em 1em;transition:all .2s ease-in-out;width:100%}:deep(button[type=submit]:hover:not(:disabled)){background-color:var(--color-primary-dark);border-color:var(--color-primary-dark)}:deep(button[type=submit]:disabled){cursor:not-allowed;opacity:.6}.loading-spinner{animation:spin 1s linear infinite;border:2px solid var(--color-white);border-radius:50%;border-top:2px solid transparent;height:16px;width:16px}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.login-footer{margin-top:1em;text-align:center}.forgot-password{margin:0}.forgot-link{color:var(--color-primary);font-size:.875rem;text-decoration:none;transition:color .2s ease-in-out}.forgot-link:hover{color:var(--color-primary-dark);text-decoration:underline}.error-message{background-color:var(--color-error-light);border:1px solid var(--color-error-border);border-radius:8px;color:var(--color-error);font-size:.875rem;margin-top:1em;padding:.75em 1em;text-align:center}@media (max-width:480px){.login-form-container{margin:1em;padding:1.5em}.login-title{font-size:1.5rem}}
133
133
  </style>
@@ -119,5 +119,5 @@ const handleResetPassword = async (data) => {
119
119
  </template>
120
120
 
121
121
  <style scoped>
122
- .error{color:red}.success{color:green}.form-message{font-size:.9rem;margin-top:1rem}:deep(.formkit-outer){margin-bottom:1rem}:deep(.formkit-label){display:block;font-weight:700;margin-bottom:.25rem}:deep(.formkit-input input[type=email]),:deep(.formkit-input input[type=password]){border:1px solid #ccc;border-radius:4px;box-sizing:border-box;padding:.75rem;width:100%}:deep(.formkit-input input[type=submit]){background-color:#333;border:none;border-radius:4px;color:#fff;cursor:pointer;padding:.75rem 1.5rem}:deep(.formkit-input input[type=submit]:disabled){background-color:#aaa;cursor:not-allowed}:deep(.formkit-messages){list-style:none;margin-top:.25rem;padding:0}:deep(.formkit-message){color:red;font-size:.8rem}
122
+ .error{color:red}.success{color:green}.form-message{font-size:.9rem;margin-top:1em}:deep(.formkit-outer){margin-bottom:1em}:deep(.formkit-label){display:block;font-weight:700;margin-bottom:.25em}:deep(.formkit-input input[type=email]),:deep(.formkit-input input[type=password]){border:1px solid var(--color-border-dark);border-radius:4px;box-sizing:border-box;padding:.75em;width:100%}:deep(.formkit-input input[type=submit]){background-color:var(--color-gray-800);border:none;border-radius:4px;color:#fff;cursor:pointer;padding:.75em 1.5em}:deep(.formkit-input input[type=submit]:disabled){background-color:var(--color-gray-500);cursor:not-allowed}:deep(.formkit-messages){list-style:none;margin-top:.25em;padding:0}:deep(.formkit-message){color:red;font-size:.8rem}
123
123
  </style>
@@ -1,4 +1,14 @@
1
- import { defineNuxtPlugin } from "#app";
2
- export default defineNuxtPlugin((_nuxtApp) => {
3
- console.log("Plugin injected by nuxt-users!");
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ import { checkTableExists } from "../utils/db";
3
+ export default defineNuxtPlugin(async (_nuxtApp) => {
4
+ if (import.meta.client) {
5
+ return;
6
+ }
7
+ const { nuxtUsers } = useRuntimeConfig();
8
+ const options = nuxtUsers;
9
+ const hasMigrationsTable = await checkTableExists(options, options.tables.migrations);
10
+ if (!hasMigrationsTable) {
11
+ useRuntimeConfig().public.nuxtUsers.tables.migrations = "";
12
+ console.warn("[Nuxt Users] \u26A0\uFE0F Migrations table does not exist, you should run the migration script to create it by running: npx nuxt-users migrate");
13
+ }
4
14
  });
@@ -1,8 +1,8 @@
1
1
  import { createError, defineEventHandler, readBody, setCookie } from "h3";
2
- import { useDb } from "../utils/db.js";
3
2
  import bcrypt from "bcrypt";
4
3
  import crypto from "node:crypto";
5
4
  import { useRuntimeConfig } from "#imports";
5
+ import { useDb } from "../../../utils/db";
6
6
  export default defineEventHandler(async (event) => {
7
7
  const body = await readBody(event);
8
8
  const { email, password } = body;
@@ -1,8 +1,8 @@
1
1
  import { createTransport } from "nodemailer";
2
2
  import crypto from "node:crypto";
3
3
  import bcrypt from "bcrypt";
4
- import { findUserByEmail, updateUserPassword } from "../utils/user.js";
5
- import { useDb } from "../utils/db.js";
4
+ import { findUserByEmail, updateUserPassword } from "../../../utils/user";
5
+ import { useDb } from "../../../utils/db";
6
6
  const TOKEN_EXPIRATION_HOURS = 1;
7
7
  export const sendPasswordResetLink = async (email, options) => {
8
8
  const user = await findUserByEmail(email, options);
@@ -0,0 +1,31 @@
1
+ class BoundableStatement {
2
+ _statement;
3
+ constructor(rawStmt) {
4
+ this._statement = rawStmt;
5
+ }
6
+ bind(...params) {
7
+ return new BoundStatement(this, params);
8
+ }
9
+ }
10
+ class BoundStatement {
11
+ #statement;
12
+ #params;
13
+ constructor(statement, params) {
14
+ this.#statement = statement;
15
+ this.#params = params;
16
+ }
17
+ bind(...params) {
18
+ return new BoundStatement(this.#statement, params);
19
+ }
20
+ all() {
21
+ return this.#statement.all(...this.#params);
22
+ }
23
+ run() {
24
+ return this.#statement.run(...this.#params);
25
+ }
26
+ get() {
27
+ return this.#statement.get(...this.#params);
28
+ }
29
+ }
30
+
31
+ export { BoundableStatement as B };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Nuxt users module",
5
5
  "repository": "rrd108/nuxt-users",
6
6
  "license": "MIT",
@@ -20,20 +20,34 @@
20
20
  }
21
21
  },
22
22
  "files": [
23
- "dist",
24
- "src/cli"
23
+ "dist"
25
24
  ],
26
25
  "bin": {
27
- "nuxt-users": "./src/cli/main.ts"
26
+ "nuxt-users": "./dist/cli.mjs"
27
+ },
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
28
41
  },
29
42
  "scripts": {
30
43
  "prepack": "nuxt-module-build build",
44
+ "postinstall": "node -e \"try { require('fs').chmodSync('./dist/cli.mjs', '755') } catch(e) {}\"",
31
45
  "predev": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
32
- "dev": "npm run dev:prepare && nuxi dev playground",
46
+ "dev": "yarn dev:prepare && nuxi dev playground",
33
47
  "dev:build": "nuxi build playground",
34
48
  "dev:prepare": "yarn nuxt-module-build build --stub && yarn nuxt-module-build prepare && nuxi prepare playground",
35
49
  "prerelease": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
36
- "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
50
+ "release": "yarn lint && yarn test && yarn prepack && changelogen --release && yarn publish && git push --follow-tags",
37
51
  "lint": "eslint .",
38
52
  "lint:fix": "eslint . --fix",
39
53
  "pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
@@ -49,15 +63,13 @@
49
63
  "db:create-password-reset-tokens-table": "tsx src/cli/create-password-reset-tokens-table.ts",
50
64
  "db:create-migrations-table": "tsx src/cli/create-migrations-table.ts",
51
65
  "db:migrate": "tsx src/cli/migrate.ts",
66
+ "db:create-empty-sqlite": "node scripts/create-empty-sqlite.js",
52
67
  "docs:dev": "vitepress dev docs",
53
68
  "docs:build": "vitepress build docs",
54
69
  "docs:preview": "vitepress preview docs",
55
- "docs:deploy": "npm run docs:build && ./scripts/deploy-docs.sh"
70
+ "docs:deploy": "yarn docs:build && ./scripts/deploy-docs.sh"
56
71
  },
57
72
  "dependencies": {
58
- "@nuxt/kit": "^3.17.6",
59
- "@types/bcrypt": "^5.0.2",
60
- "@types/pg": "^8.15.4",
61
73
  "bcrypt": "^6.0.0",
62
74
  "better-sqlite3": "^12.2.0",
63
75
  "citty": "^0.1.6",
@@ -66,15 +78,21 @@
66
78
  "nodemailer": "^7.0.5",
67
79
  "pg": "^8.16.3"
68
80
  },
81
+ "peerDependencies": {
82
+ "@nuxt/kit": "^3.17.6"
83
+ },
69
84
  "devDependencies": {
70
85
  "@formkit/nuxt": "^1.6.9",
71
86
  "@nuxt/devtools": "^2.6.2",
72
87
  "@nuxt/eslint-config": "^1.5.2",
88
+ "@nuxt/kit": "^3.17.6",
73
89
  "@nuxt/module-builder": "^1.0.1",
74
90
  "@nuxt/schema": "^3.17.6",
75
91
  "@nuxt/test-utils": "^3.19.2",
92
+ "@types/bcrypt": "^5.0.2",
76
93
  "@types/node": "latest",
77
94
  "@types/nodemailer": "^6.4.17",
95
+ "@types/pg": "^8.15.4",
78
96
  "changelogen": "^0.6.2",
79
97
  "eslint": "^9.30.1",
80
98
  "nuxt": "^3.17.6",
@@ -1,2 +0,0 @@
1
- import type { ModuleOptions } from '../../../types.js';
2
- export declare const createMigrationsTable: (options: ModuleOptions) => Promise<void>;
@@ -1,35 +0,0 @@
1
- import { useDb } from "./db.js";
2
- export const createMigrationsTable = async (options) => {
3
- const connectorName = options.connector.name;
4
- const db = await useDb(options);
5
- const tableName = "migrations";
6
- console.log(`[DB:Create Migrations ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
7
- if (connectorName === "sqlite") {
8
- await db.sql`
9
- CREATE TABLE IF NOT EXISTS {${tableName}} (
10
- id INTEGER PRIMARY KEY AUTOINCREMENT,
11
- name TEXT NOT NULL UNIQUE,
12
- executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
13
- )
14
- `;
15
- }
16
- if (connectorName === "mysql") {
17
- await db.sql`
18
- CREATE TABLE IF NOT EXISTS {${tableName}} (
19
- id INT AUTO_INCREMENT PRIMARY KEY,
20
- name VARCHAR(255) NOT NULL UNIQUE,
21
- executed_at DATETIME DEFAULT CURRENT_TIMESTAMP
22
- )
23
- `;
24
- }
25
- if (connectorName === "postgresql") {
26
- await db.sql`
27
- CREATE TABLE IF NOT EXISTS {${tableName}} (
28
- id SERIAL PRIMARY KEY,
29
- name VARCHAR(255) NOT NULL UNIQUE,
30
- executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
31
- )
32
- `;
33
- }
34
- console.log(`[DB:Create Migrations ${connectorName} Table] successfull \u2705`);
35
- };
@@ -1,2 +0,0 @@
1
- import type { ModuleOptions } from '../../../types.js';
2
- export declare const createPasswordResetTokensTable: (options: ModuleOptions) => Promise<void>;
@@ -1,40 +0,0 @@
1
- import { useDb } from "./db.js";
2
- export const createPasswordResetTokensTable = async (options) => {
3
- const connectorName = options.connector.name;
4
- const db = await useDb(options);
5
- const tableName = options.tables.passwordResetTokens;
6
- console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
7
- if (connectorName === "sqlite") {
8
- await db.sql`
9
- CREATE TABLE IF NOT EXISTS {${tableName}} (
10
- id INTEGER PRIMARY KEY AUTOINCREMENT,
11
- email TEXT NOT NULL,
12
- token TEXT NOT NULL UNIQUE,
13
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
14
- )
15
- `;
16
- }
17
- if (connectorName === "mysql") {
18
- await db.sql`
19
- CREATE TABLE IF NOT EXISTS {${tableName}} (
20
- id INT AUTO_INCREMENT PRIMARY KEY,
21
- email VARCHAR(255) NOT NULL,
22
- token VARCHAR(255) NOT NULL UNIQUE,
23
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
24
- )
25
- `;
26
- }
27
- if (connectorName === "postgresql") {
28
- await db.sql`
29
- CREATE TABLE IF NOT EXISTS {${tableName}} (
30
- id SERIAL PRIMARY KEY,
31
- email VARCHAR(255) NOT NULL,
32
- token VARCHAR(255) NOT NULL UNIQUE,
33
- created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
34
- )
35
- `;
36
- }
37
- await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_email ON {${tableName}} (email)`;
38
- await db.sql`CREATE INDEX IF NOT EXISTS idx_password_reset_tokens_token ON {${tableName}} (token)`;
39
- console.log(`[DB:Create Password Reset Tokens ${connectorName} Table] Fields: id, email, token, created_at \u2705`);
40
- };
@@ -1,2 +0,0 @@
1
- import type { ModuleOptions } from '../../../types.js';
2
- export declare const createPersonalAccessTokensTable: (options: ModuleOptions) => Promise<void>;
@@ -1,56 +0,0 @@
1
- import { useDb } from "./db.js";
2
- export const createPersonalAccessTokensTable = async (options) => {
3
- const connectorName = options.connector.name;
4
- const db = await useDb(options);
5
- const tableName = options.tables.personalAccessTokens;
6
- console.log(`[DB:Create Personal Access Tokens ${connectorName} Table] Creating ${tableName} table with ${connectorName} connector...`);
7
- if (connectorName === "sqlite") {
8
- await db.sql`
9
- CREATE TABLE IF NOT EXISTS {${tableName}} (
10
- id INTEGER PRIMARY KEY AUTOINCREMENT,
11
- tokenable_type TEXT NOT NULL,
12
- tokenable_id INTEGER NOT NULL,
13
- name TEXT NOT NULL,
14
- token TEXT NOT NULL UNIQUE,
15
- abilities TEXT,
16
- last_used_at DATETIME,
17
- expires_at DATETIME,
18
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
19
- updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
20
- )
21
- `;
22
- }
23
- if (connectorName === "mysql") {
24
- await db.sql`
25
- CREATE TABLE IF NOT EXISTS {${tableName}} (
26
- id INT AUTO_INCREMENT PRIMARY KEY,
27
- tokenable_type VARCHAR(255) NOT NULL,
28
- tokenable_id INT NOT NULL,
29
- name VARCHAR(255) NOT NULL,
30
- token VARCHAR(255) NOT NULL UNIQUE,
31
- abilities TEXT,
32
- last_used_at DATETIME,
33
- expires_at DATETIME,
34
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
35
- updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
36
- )
37
- `;
38
- }
39
- if (connectorName === "postgresql") {
40
- await db.sql`
41
- CREATE TABLE IF NOT EXISTS {${tableName}} (
42
- id SERIAL PRIMARY KEY,
43
- tokenable_type VARCHAR(255) NOT NULL,
44
- tokenable_id INT NOT NULL,
45
- name VARCHAR(255) NOT NULL,
46
- token VARCHAR(255) NOT NULL UNIQUE,
47
- abilities TEXT,
48
- last_used_at TIMESTAMPTZ,
49
- expires_at TIMESTAMPTZ,
50
- created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
51
- updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
52
- )
53
- `;
54
- }
55
- 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`);
56
- };
@@ -1 +0,0 @@
1
- export { createUser } from './user.js';
@@ -1 +0,0 @@
1
- export { createUser } from "./user.js";
@@ -1,2 +0,0 @@
1
- import type { ModuleOptions } from '../../../types.js';
2
- export declare const createUsersTable: (options: ModuleOptions) => Promise<void>;
@@ -1,44 +0,0 @@
1
- import { useDb } from "./db.js";
2
- export const createUsersTable = async (options) => {
3
- const connectorName = options.connector.name;
4
- const db = await useDb(options);
5
- const tableName = options.tables.users;
6
- console.log(`[DB:Create ${connectorName} Users Table] Creating ${tableName}...`);
7
- if (connectorName === "sqlite") {
8
- await db.sql`
9
- CREATE TABLE IF NOT EXISTS {${tableName}} (
10
- id INTEGER PRIMARY KEY AUTOINCREMENT,
11
- email TEXT NOT NULL UNIQUE,
12
- name TEXT NOT NULL,
13
- password TEXT NOT NULL,
14
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
15
- updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
16
- )
17
- `;
18
- }
19
- if (connectorName === "mysql") {
20
- await db.sql`
21
- CREATE TABLE IF NOT EXISTS {${tableName}} (
22
- id INT AUTO_INCREMENT PRIMARY KEY,
23
- email VARCHAR(255) NOT NULL UNIQUE,
24
- name VARCHAR(255) NOT NULL,
25
- password VARCHAR(255) NOT NULL,
26
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
27
- updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
28
- )
29
- `;
30
- }
31
- if (connectorName === "postgresql") {
32
- await db.sql`
33
- CREATE TABLE IF NOT EXISTS {${tableName}} (
34
- id SERIAL PRIMARY KEY,
35
- email VARCHAR(255) NOT NULL UNIQUE,
36
- name VARCHAR(255) NOT NULL,
37
- password VARCHAR(255) NOT NULL,
38
- created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
39
- updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
40
- )
41
- `;
42
- }
43
- console.log(`[DB:Create ${connectorName} Users Table] Fields: id, email, name, password, created_at, updated_at \u2705`);
44
- };
@@ -1,8 +0,0 @@
1
- import type { ModuleOptions } from '../../../types.js';
2
- export declare const getConnector: (name: string) => Promise<typeof import("db0/connectors/mysql2").default | typeof import("db0/connectors/postgresql").default | typeof import("db0/connectors/better-sqlite3").default>;
3
- export declare const useDb: (options: ModuleOptions) => Promise<import("db0").Database<import("db0").Connector<Database.Database>>>;
4
- export declare const checkPasswordResetTokensTableExists: (options: ModuleOptions) => Promise<boolean>;
5
- export declare const checkUsersTableExists: (options: ModuleOptions) => Promise<boolean>;
6
- export declare const checkPersonalAccessTokensTableExists: (options: ModuleOptions) => Promise<boolean>;
7
- export declare const checkTableExists: (options: ModuleOptions, tableName: string) => Promise<boolean>;
8
- export declare const hasAnyUsers: (options: ModuleOptions) => Promise<boolean>;
@@ -1,49 +0,0 @@
1
- import { createDatabase } from "db0";
2
- export const getConnector = async (name) => {
3
- switch (name) {
4
- case "mysql":
5
- return (await import("db0/connectors/mysql2")).default;
6
- case "postgresql":
7
- return (await import("db0/connectors/postgresql")).default;
8
- case "sqlite":
9
- return (await import("db0/connectors/better-sqlite3")).default;
10
- default:
11
- throw new Error(`Unsupported database connector: ${name}`);
12
- }
13
- };
14
- export const useDb = async (options) => {
15
- const connectorName = options.connector.name;
16
- const connector = await getConnector(connectorName);
17
- const connectorOptions = { ...options.connector.options };
18
- if (connectorName !== "sqlite") {
19
- delete connectorOptions.path;
20
- }
21
- return createDatabase(connector(connectorOptions));
22
- };
23
- export const checkPasswordResetTokensTableExists = async (options) => {
24
- return await checkTableExists(options, options.tables.passwordResetTokens);
25
- };
26
- export const checkUsersTableExists = async (options) => {
27
- return await checkTableExists(options, options.tables.users);
28
- };
29
- export const checkPersonalAccessTokensTableExists = async (options) => {
30
- return await checkTableExists(options, options.tables.personalAccessTokens);
31
- };
32
- export const checkTableExists = async (options, tableName) => {
33
- const db = await useDb(options);
34
- try {
35
- await db.sql`SELECT 1 FROM {${tableName}} LIMIT 1`;
36
- return true;
37
- } catch {
38
- return false;
39
- }
40
- };
41
- export const hasAnyUsers = async (options) => {
42
- const db = await useDb(options);
43
- try {
44
- const users = await db.sql`SELECT COUNT(*) as count FROM {${options.tables.users}}`;
45
- return users.rows?.[0]?.count > 0;
46
- } catch {
47
- return false;
48
- }
49
- };
@@ -1,4 +0,0 @@
1
- import type { ModuleOptions } from '../../../types.js';
2
- export declare const getAppliedMigrations: (options: ModuleOptions) => Promise<string[]>;
3
- export declare const markMigrationAsApplied: (options: ModuleOptions, migrationName: string) => Promise<void>;
4
- export declare const runMigrations: (options: ModuleOptions) => Promise<void>;
@@ -1,63 +0,0 @@
1
- import { useDb } from "./db.js";
2
- import { createUsersTable } from "./create-users-table.js";
3
- import { createPersonalAccessTokensTable } from "./create-personal-access-tokens-table.js";
4
- import { createPasswordResetTokensTable } from "./create-password-reset-tokens-table.js";
5
- import { createMigrationsTable } from "./create-migrations-table.js";
6
- const migrations = [
7
- {
8
- name: "create_migrations_table",
9
- run: createMigrationsTable
10
- },
11
- {
12
- name: "create_users_table",
13
- run: createUsersTable
14
- },
15
- {
16
- name: "create_personal_access_tokens_table",
17
- run: createPersonalAccessTokensTable
18
- },
19
- {
20
- name: "create_password_reset_tokens_table",
21
- run: createPasswordResetTokensTable
22
- }
23
- ];
24
- export const getAppliedMigrations = async (options) => {
25
- const db = await useDb(options);
26
- try {
27
- const result = await db.sql`SELECT name FROM migrations ORDER BY id`;
28
- return result.rows.map((row) => row.name);
29
- } catch {
30
- return [];
31
- }
32
- };
33
- export const markMigrationAsApplied = async (options, migrationName) => {
34
- const db = await useDb(options);
35
- await db.sql`INSERT INTO migrations (name) VALUES (${migrationName})`;
36
- };
37
- export const runMigrations = async (options) => {
38
- console.log("[Nuxt Users] Starting migration system...");
39
- await createMigrationsTable(options);
40
- const appliedMigrations = await getAppliedMigrations(options);
41
- console.log(`[Nuxt Users] Applied migrations: ${appliedMigrations.join(", ")}`);
42
- const pendingMigrations = migrations.filter((migration) => !appliedMigrations.includes(migration.name));
43
- if (pendingMigrations.length === 0) {
44
- console.log("[Nuxt Users] No pending migrations to run.");
45
- return;
46
- }
47
- console.log(`[Nuxt Users] Found ${pendingMigrations.length} pending migrations:`);
48
- pendingMigrations.forEach((migration) => {
49
- console.log(` - ${migration.name}`);
50
- });
51
- for (const migration of pendingMigrations) {
52
- console.log(`[Nuxt Users] Running migration: ${migration.name}`);
53
- try {
54
- await migration.run(options);
55
- await markMigrationAsApplied(options, migration.name);
56
- console.log(`[Nuxt Users] \u2713 Migration ${migration.name} successfull \u2705`);
57
- } catch (error) {
58
- console.error(`[Nuxt Users] \u2717 Migration ${migration.name} failed:`, error);
59
- throw error;
60
- }
61
- }
62
- console.log("[Nuxt Users] All migrations successfull \u2705");
63
- };