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.
- package/.vscode/settings.json +18 -0
- package/CHANGELOG.md +112 -0
- package/README.md +0 -2
- package/dist/chunks/better-sqlite3.mjs +45 -0
- package/dist/chunks/mysql2.mjs +49 -0
- package/dist/chunks/postgresql.mjs +58 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +587 -0
- package/dist/module.d.mts +1 -3
- package/dist/module.d.ts +55 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +11 -81
- package/dist/runtime/assets/colors.css +1 -0
- package/dist/runtime/components/ForgotPasswordForm.vue +1 -1
- package/dist/runtime/components/LoginForm.vue +1 -1
- package/dist/runtime/components/ResetPasswordForm.vue +1 -1
- package/dist/runtime/plugin.js +13 -3
- package/dist/runtime/server/api/login.post.js +1 -1
- package/dist/runtime/server/services/password.js +2 -2
- package/dist/shared/nuxt-users.C9d5M6B1.mjs +31 -0
- package/package.json +28 -12
- 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,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
|
-
})
|
package/src/cli/utils.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { ModuleOptions, DatabaseConfig } from '../types'
|
|
2
|
-
|
|
3
|
-
export const defaultOptions: ModuleOptions = {
|
|
4
|
-
connector: {
|
|
5
|
-
name: 'sqlite',
|
|
6
|
-
options: {
|
|
7
|
-
path: './data/default.sqlite3',
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
tables: {
|
|
11
|
-
users: 'users',
|
|
12
|
-
personalAccessTokens: 'personal_access_tokens',
|
|
13
|
-
passwordResetTokens: 'password_reset_tokens',
|
|
14
|
-
},
|
|
15
|
-
mailer: {
|
|
16
|
-
host: 'smtp.ethereal.email',
|
|
17
|
-
port: 587,
|
|
18
|
-
secure: false,
|
|
19
|
-
auth: {
|
|
20
|
-
user: 'user@ethereal.email',
|
|
21
|
-
pass: 'password',
|
|
22
|
-
},
|
|
23
|
-
defaults: {
|
|
24
|
-
from: '"Nuxt Users Module" <noreply@example.com>',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
passwordResetBaseUrl: 'http://localhost:3000',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const getOptionsFromEnv = (): ModuleOptions => {
|
|
31
|
-
const connectorName = process.env.DB_CONNECTOR || 'sqlite'
|
|
32
|
-
|
|
33
|
-
let connectorOptions: DatabaseConfig
|
|
34
|
-
|
|
35
|
-
switch (connectorName) {
|
|
36
|
-
case 'sqlite':
|
|
37
|
-
connectorOptions = {
|
|
38
|
-
path: process.env.DB_PATH || './data/default.sqlite3',
|
|
39
|
-
}
|
|
40
|
-
break
|
|
41
|
-
case 'mysql':
|
|
42
|
-
connectorOptions = {
|
|
43
|
-
host: process.env.DB_HOST || 'localhost',
|
|
44
|
-
port: Number.parseInt(process.env.DB_PORT || '3306'),
|
|
45
|
-
user: process.env.DB_USER || 'root',
|
|
46
|
-
password: process.env.DB_PASSWORD || '',
|
|
47
|
-
database: process.env.DB_NAME || 'nuxt_users',
|
|
48
|
-
}
|
|
49
|
-
break
|
|
50
|
-
case 'postgresql':
|
|
51
|
-
connectorOptions = {
|
|
52
|
-
host: process.env.DB_HOST || 'localhost',
|
|
53
|
-
port: Number.parseInt(process.env.DB_PORT || '5432'),
|
|
54
|
-
user: process.env.DB_USER || 'postgres',
|
|
55
|
-
password: process.env.DB_PASSWORD || '',
|
|
56
|
-
database: process.env.DB_NAME || 'nuxt_users',
|
|
57
|
-
}
|
|
58
|
-
break
|
|
59
|
-
default:
|
|
60
|
-
throw new Error(`Unsupported database connector: ${connectorName}`)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
...defaultOptions,
|
|
65
|
-
connector: {
|
|
66
|
-
name: connectorName as 'sqlite' | 'mysql' | 'postgresql',
|
|
67
|
-
options: connectorOptions,
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
}
|