nuxt-users 1.1.2 → 1.1.4
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/.vscode/settings.json +18 -0
- package/CHANGELOG.md +174 -0
- package/README.md +12 -2
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +269 -0
- package/dist/module.d.mts +1 -51
- package/dist/module.d.ts +7 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +11 -81
- package/dist/runtime/assets/colors.css +1 -0
- 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 +13 -3
- 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 +59 -27
- package/data/default.sqlite3 +0 -0
- package/dist/runtime/server/utils/create-migrations-table.d.ts +0 -2
- package/dist/runtime/server/utils/create-migrations-table.js +0 -35
- package/dist/runtime/server/utils/create-password-reset-tokens-table.d.ts +0 -2
- package/dist/runtime/server/utils/create-password-reset-tokens-table.js +0 -40
- package/dist/runtime/server/utils/create-personal-access-tokens-table.d.ts +0 -2
- package/dist/runtime/server/utils/create-personal-access-tokens-table.js +0 -56
- package/dist/runtime/server/utils/create-user.d.ts +0 -1
- package/dist/runtime/server/utils/create-user.js +0 -1
- package/dist/runtime/server/utils/create-users-table.d.ts +0 -2
- package/dist/runtime/server/utils/create-users-table.js +0 -44
- package/dist/runtime/server/utils/db.d.ts +0 -8
- package/dist/runtime/server/utils/db.js +0 -61
- package/dist/runtime/server/utils/migrate.d.ts +0 -4
- package/dist/runtime/server/utils/migrate.js +0 -63
- package/dist/runtime/server/utils/user.d.ts +0 -21
- package/dist/runtime/server/utils/user.js +0 -50
- package/src/cli/create-migrations-table.ts +0 -24
- package/src/cli/create-password-reset-tokens-table.ts +0 -24
- package/src/cli/create-personal-access-tokens-table.ts +0 -24
- package/src/cli/create-user.ts +0 -40
- package/src/cli/create-users-table.ts +0 -24
- package/src/cli/main.ts +0 -28
- package/src/cli/migrate.ts +0 -24
- package/src/cli/project-info.ts +0 -45
- package/src/cli/utils.ts +0 -70
|
@@ -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,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,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,61 +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
|
-
if (connectorName === "mysql") {
|
|
22
|
-
connectorOptions.connectTimeout = 5e3;
|
|
23
|
-
connectorOptions.acquireTimeout = 5e3;
|
|
24
|
-
}
|
|
25
|
-
if (connectorName === "postgresql") {
|
|
26
|
-
connectorOptions.connectionTimeoutMillis = 5e3;
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
return createDatabase(connector(connectorOptions));
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.warn(`[Nuxt Users DB] \u26A0\uFE0F Failed to connect to ${connectorName} database:`, error instanceof Error ? error.message : "Unknown error");
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
export const checkPasswordResetTokensTableExists = async (options) => {
|
|
36
|
-
return await checkTableExists(options, options.tables.passwordResetTokens);
|
|
37
|
-
};
|
|
38
|
-
export const checkUsersTableExists = async (options) => {
|
|
39
|
-
return await checkTableExists(options, options.tables.users);
|
|
40
|
-
};
|
|
41
|
-
export const checkPersonalAccessTokensTableExists = async (options) => {
|
|
42
|
-
return await checkTableExists(options, options.tables.personalAccessTokens);
|
|
43
|
-
};
|
|
44
|
-
export const checkTableExists = async (options, tableName) => {
|
|
45
|
-
try {
|
|
46
|
-
const db = await useDb(options);
|
|
47
|
-
await db.sql`SELECT 1 FROM {${tableName}} LIMIT 1`;
|
|
48
|
-
return true;
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
export const hasAnyUsers = async (options) => {
|
|
54
|
-
try {
|
|
55
|
-
const db = await useDb(options);
|
|
56
|
-
const users = await db.sql`SELECT COUNT(*) as count FROM {${options.tables.users}}`;
|
|
57
|
-
return users.rows?.[0]?.count > 0;
|
|
58
|
-
} catch {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
@@ -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
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ModuleOptions, User } from '../../../types.js';
|
|
2
|
-
interface CreateUserParams {
|
|
3
|
-
email: string;
|
|
4
|
-
name: string;
|
|
5
|
-
password: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Creates a new user in the database.
|
|
9
|
-
* Hashes the password before storing.
|
|
10
|
-
*/
|
|
11
|
-
export declare const createUser: (userData: CreateUserParams, options: ModuleOptions) => Promise<Omit<User, "password">>;
|
|
12
|
-
/**
|
|
13
|
-
* Finds a user by their email address.
|
|
14
|
-
*/
|
|
15
|
-
export declare const findUserByEmail: (email: string, options: ModuleOptions) => Promise<User | null>;
|
|
16
|
-
/**
|
|
17
|
-
* Updates a user's password.
|
|
18
|
-
* Hashes the new password before storing.
|
|
19
|
-
*/
|
|
20
|
-
export declare const updateUserPassword: (email: string, newPassword: string, options: ModuleOptions) => Promise<void>;
|
|
21
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useDb } from "./db.js";
|
|
2
|
-
import bcrypt from "bcrypt";
|
|
3
|
-
export const createUser = async (userData, options) => {
|
|
4
|
-
const db = await useDb(options);
|
|
5
|
-
const usersTable = options.tables.users;
|
|
6
|
-
const hashedPassword = await bcrypt.hash(userData.password, 10);
|
|
7
|
-
await db.sql`
|
|
8
|
-
INSERT INTO {${usersTable}} (email, name, password, created_at, updated_at)
|
|
9
|
-
VALUES (${userData.email}, ${userData.name}, ${hashedPassword}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
|
10
|
-
`;
|
|
11
|
-
const result = await db.sql`SELECT id, email, name, created_at, updated_at FROM {${usersTable}} WHERE email = ${userData.email}`;
|
|
12
|
-
if (result.rows.length === 0) {
|
|
13
|
-
throw new Error("Failed to retrieve created user.");
|
|
14
|
-
}
|
|
15
|
-
const user = result.rows[0];
|
|
16
|
-
return {
|
|
17
|
-
id: user.id,
|
|
18
|
-
email: user.email,
|
|
19
|
-
name: user.name,
|
|
20
|
-
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
21
|
-
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export const findUserByEmail = async (email, options) => {
|
|
25
|
-
const db = await useDb(options);
|
|
26
|
-
const usersTable = options.tables.users;
|
|
27
|
-
const result = await db.sql`SELECT * FROM {${usersTable}} WHERE email = ${email}`;
|
|
28
|
-
if (result.rows.length === 0) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const user = result.rows[0];
|
|
32
|
-
return {
|
|
33
|
-
id: user.id,
|
|
34
|
-
email: user.email,
|
|
35
|
-
name: user.name,
|
|
36
|
-
password: user.password,
|
|
37
|
-
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
38
|
-
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
export const updateUserPassword = async (email, newPassword, options) => {
|
|
42
|
-
const db = await useDb(options);
|
|
43
|
-
const usersTable = options.tables.users;
|
|
44
|
-
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
45
|
-
await db.sql`
|
|
46
|
-
UPDATE {${usersTable}}
|
|
47
|
-
SET password = ${hashedPassword}, updated_at = CURRENT_TIMESTAMP
|
|
48
|
-
WHERE email = ${email}
|
|
49
|
-
`;
|
|
50
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { createMigrationsTable } from '../runtime/server/utils/create-migrations-table'
|
|
3
|
-
import { getOptionsFromEnv } from './utils'
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'create-migrations-table',
|
|
8
|
-
description: 'Create the migrations table in the database'
|
|
9
|
-
},
|
|
10
|
-
async run() {
|
|
11
|
-
console.log('[Nuxt Users] Creating migrations table...')
|
|
12
|
-
|
|
13
|
-
const options = getOptionsFromEnv()
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await createMigrationsTable(options)
|
|
17
|
-
console.log('[Nuxt Users] Migrations table created successfully!')
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('[DB:Create Migrations Table] Error:', error)
|
|
21
|
-
process.exit(1)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { createPasswordResetTokensTable } from '../runtime/server/utils/create-password-reset-tokens-table'
|
|
3
|
-
import { getOptionsFromEnv } from './utils'
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'create-password-reset-tokens-table',
|
|
8
|
-
description: 'Create the password reset tokens table in the database'
|
|
9
|
-
},
|
|
10
|
-
async run() {
|
|
11
|
-
console.log('[Nuxt Users] Creating password reset tokens table...')
|
|
12
|
-
|
|
13
|
-
const options = getOptionsFromEnv()
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await createPasswordResetTokensTable(options)
|
|
17
|
-
console.log('[Nuxt Users] Password reset tokens table created successfully!')
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('[DB:Create Password Reset Tokens Table] Error:', error)
|
|
21
|
-
process.exit(1)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { createPersonalAccessTokensTable } from '../runtime/server/utils/create-personal-access-tokens-table'
|
|
3
|
-
import { getOptionsFromEnv } from './utils'
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'create-personal-access-tokens-table',
|
|
8
|
-
description: 'Create the personal access tokens table in the database'
|
|
9
|
-
},
|
|
10
|
-
async run() {
|
|
11
|
-
console.log('[Nuxt Users] Creating personal access tokens table...')
|
|
12
|
-
|
|
13
|
-
const options = getOptionsFromEnv()
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await createPersonalAccessTokensTable(options)
|
|
17
|
-
console.log('[Nuxt Users] Personal access tokens table created successfully!')
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('[DB:Create Personal Access Tokens Table] Error:', error)
|
|
21
|
-
process.exit(1)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
package/src/cli/create-user.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { createUser } from '../runtime/server/utils/user'
|
|
3
|
-
import { getOptionsFromEnv } from './utils'
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'create-user',
|
|
8
|
-
description: 'Create a new user in the database'
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
email: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
description: 'User email address',
|
|
14
|
-
required: true
|
|
15
|
-
},
|
|
16
|
-
name: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
description: 'User full name',
|
|
19
|
-
required: true
|
|
20
|
-
},
|
|
21
|
-
password: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
description: 'User password',
|
|
24
|
-
required: true
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
async run({ args }) {
|
|
28
|
-
const { email, name, password } = args
|
|
29
|
-
const options = getOptionsFromEnv()
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const user = await createUser({ email, name, password }, options)
|
|
33
|
-
console.log(`[DB:Create User] User created successfully: ${user.email}`)
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error('[DB:Create User] Error:', error)
|
|
37
|
-
process.exit(1)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { createUsersTable } from '../runtime/server/utils/create-users-table'
|
|
3
|
-
import { getOptionsFromEnv } from './utils'
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'create-users-table',
|
|
8
|
-
description: 'Create the users table in the database'
|
|
9
|
-
},
|
|
10
|
-
async run() {
|
|
11
|
-
console.log('[Nuxt Users] Creating users table...')
|
|
12
|
-
|
|
13
|
-
const options = getOptionsFromEnv()
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await createUsersTable(options)
|
|
17
|
-
console.log('[Nuxt Users] Users table created successfully!')
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('[DB:Create Users Table] Error:', error)
|
|
21
|
-
process.exit(1)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
package/src/cli/main.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { defineCommand, runMain } from 'citty'
|
|
3
|
-
import migrate from './migrate'
|
|
4
|
-
import createUser from './create-user'
|
|
5
|
-
import createUsersTable from './create-users-table'
|
|
6
|
-
import createPersonalAccessTokensTable from './create-personal-access-tokens-table'
|
|
7
|
-
import createPasswordResetTokensTable from './create-password-reset-tokens-table'
|
|
8
|
-
import createMigrationsTable from './create-migrations-table'
|
|
9
|
-
import projectInfo from './project-info'
|
|
10
|
-
|
|
11
|
-
const main = defineCommand({
|
|
12
|
-
meta: {
|
|
13
|
-
name: 'nuxt-users',
|
|
14
|
-
description: 'CLI for Nuxt Users Module - Manage users, migrations, and database operations',
|
|
15
|
-
version: '1.1.0'
|
|
16
|
-
},
|
|
17
|
-
subCommands: {
|
|
18
|
-
migrate,
|
|
19
|
-
'create-user': createUser,
|
|
20
|
-
'create-users-table': createUsersTable,
|
|
21
|
-
'create-personal-access-tokens-table': createPersonalAccessTokensTable,
|
|
22
|
-
'create-password-reset-tokens-table': createPasswordResetTokensTable,
|
|
23
|
-
'create-migrations-table': createMigrationsTable,
|
|
24
|
-
'project-info': projectInfo
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
runMain(main)
|
package/src/cli/migrate.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { runMigrations } from '../runtime/server/utils/migrate'
|
|
3
|
-
import { getOptionsFromEnv } from './utils'
|
|
4
|
-
|
|
5
|
-
export default defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'migrate',
|
|
8
|
-
description: 'Run database migrations for the Nuxt Users module'
|
|
9
|
-
},
|
|
10
|
-
async run() {
|
|
11
|
-
console.log('[Nuxt Users] Starting migration system...')
|
|
12
|
-
|
|
13
|
-
const options = getOptionsFromEnv()
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await runMigrations(options)
|
|
17
|
-
console.log('[Nuxt Users] Migration completed successfully!')
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('[Nuxt Users] Migration failed:', error)
|
|
21
|
-
process.exit(1)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
package/src/cli/project-info.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from 'citty'
|
|
2
|
-
import { loadNuxt } from '@nuxt/kit'
|
|
3
|
-
|
|
4
|
-
export default defineCommand({
|
|
5
|
-
meta: {
|
|
6
|
-
name: 'project-info',
|
|
7
|
-
description: 'Get information about the Nuxt project and module configuration'
|
|
8
|
-
},
|
|
9
|
-
async run() {
|
|
10
|
-
try {
|
|
11
|
-
console.log('[Nuxt Users] Loading Nuxt project...')
|
|
12
|
-
const nuxt = await loadNuxt({ cwd: process.cwd() })
|
|
13
|
-
|
|
14
|
-
console.log('✅ Nuxt project loaded successfully!')
|
|
15
|
-
console.log('📁 Source directory:', nuxt.options.srcDir)
|
|
16
|
-
console.log('🌐 Base URL:', nuxt.options.app?.baseURL || '/')
|
|
17
|
-
|
|
18
|
-
// Check if nuxt-users module is configured
|
|
19
|
-
const nuxtUsersConfig = nuxt.options.runtimeConfig?.nuxtUsers
|
|
20
|
-
if (nuxtUsersConfig) {
|
|
21
|
-
console.log('🔧 Nuxt Users module configuration:')
|
|
22
|
-
console.log(' Database connector:', nuxtUsersConfig.connector?.name)
|
|
23
|
-
console.log(' Users table:', nuxtUsersConfig.tables?.users)
|
|
24
|
-
console.log(' Personal access tokens table:', nuxtUsersConfig.tables?.personalAccessTokens)
|
|
25
|
-
console.log(' Password reset tokens table:', nuxtUsersConfig.tables?.passwordResetTokens)
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
console.log('⚠️ Nuxt Users module not configured in runtime config')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Check public runtime config
|
|
32
|
-
const publicConfig = nuxt.options.runtimeConfig?.public?.nuxtUsers
|
|
33
|
-
if (publicConfig) {
|
|
34
|
-
console.log('🌍 Public runtime config:')
|
|
35
|
-
console.log(' Users table exists:', publicConfig.tables?.users)
|
|
36
|
-
console.log(' Personal access tokens table exists:', publicConfig.tables?.personalAccessTokens)
|
|
37
|
-
console.log(' Password reset tokens table exists:', publicConfig.tables?.passwordResetTokens)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error('❌ Could not load Nuxt project:', error)
|
|
42
|
-
process.exit(1)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})
|