nuxt-users 1.1.0
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/README.md +69 -0
- package/dist/module.d.mts +49 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +122 -0
- package/dist/runtime/components/ForgotPasswordForm.vue +79 -0
- package/dist/runtime/components/ForgotPasswordForm.vue.d.ts +2 -0
- package/dist/runtime/components/LoginForm.vue +133 -0
- package/dist/runtime/components/LoginForm.vue.d.ts +35 -0
- package/dist/runtime/components/ResetPasswordForm.vue +123 -0
- package/dist/runtime/components/ResetPasswordForm.vue.d.ts +2 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +4 -0
- package/dist/runtime/server/api/auth/forgot-password.post.d.ts +4 -0
- package/dist/runtime/server/api/auth/forgot-password.post.js +26 -0
- package/dist/runtime/server/api/auth/reset-password.post.d.ts +4 -0
- package/dist/runtime/server/api/auth/reset-password.post.js +48 -0
- package/dist/runtime/server/api/login.post.d.ts +10 -0
- package/dist/runtime/server/api/login.post.js +57 -0
- package/dist/runtime/server/services/password.d.ts +14 -0
- package/dist/runtime/server/services/password.js +113 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/create-migrations-table.d.ts +2 -0
- package/dist/runtime/server/utils/create-migrations-table.js +37 -0
- package/dist/runtime/server/utils/create-password-reset-tokens-table.d.ts +2 -0
- package/dist/runtime/server/utils/create-password-reset-tokens-table.js +42 -0
- package/dist/runtime/server/utils/create-personal-access-tokens-table.d.ts +2 -0
- package/dist/runtime/server/utils/create-personal-access-tokens-table.js +58 -0
- package/dist/runtime/server/utils/create-user.d.ts +1 -0
- package/dist/runtime/server/utils/create-user.js +1 -0
- package/dist/runtime/server/utils/create-users-table.d.ts +2 -0
- package/dist/runtime/server/utils/create-users-table.js +46 -0
- package/dist/runtime/server/utils/db.d.ts +7 -0
- package/dist/runtime/server/utils/db.js +45 -0
- package/dist/runtime/server/utils/migrate.d.ts +4 -0
- package/dist/runtime/server/utils/migrate.js +68 -0
- package/dist/runtime/server/utils/user.d.ts +21 -0
- package/dist/runtime/server/utils/user.js +57 -0
- package/dist/types.d.mts +7 -0
- package/package.json +82 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createDatabase } from "db0";
|
|
2
|
+
import { getConnector } from "./db.js";
|
|
3
|
+
import bcrypt from "bcrypt";
|
|
4
|
+
export const createUser = async (userData, options) => {
|
|
5
|
+
const connectorName = options.connector.name;
|
|
6
|
+
const connector = await getConnector(connectorName);
|
|
7
|
+
const db = createDatabase(connector(options.connector.options));
|
|
8
|
+
const usersTable = options.tables.users;
|
|
9
|
+
const hashedPassword = await bcrypt.hash(userData.password, 10);
|
|
10
|
+
await db.sql`
|
|
11
|
+
INSERT INTO {${usersTable}} (email, name, password, created_at, updated_at)
|
|
12
|
+
VALUES (${userData.email}, ${userData.name}, ${hashedPassword}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
|
13
|
+
`;
|
|
14
|
+
const result = await db.sql`SELECT id, email, name, created_at, updated_at FROM {${usersTable}} WHERE email = ${userData.email}`;
|
|
15
|
+
if (result.rows.length === 0) {
|
|
16
|
+
throw new Error("Failed to retrieve created user.");
|
|
17
|
+
}
|
|
18
|
+
const user = result.rows[0];
|
|
19
|
+
return {
|
|
20
|
+
id: user.id,
|
|
21
|
+
email: user.email,
|
|
22
|
+
name: user.name,
|
|
23
|
+
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
24
|
+
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export const findUserByEmail = async (email, options) => {
|
|
28
|
+
const connectorName = options.connector.name;
|
|
29
|
+
const connector = await getConnector(connectorName);
|
|
30
|
+
const db = createDatabase(connector(options.connector.options));
|
|
31
|
+
const usersTable = options.tables.users;
|
|
32
|
+
const result = await db.sql`SELECT * FROM {${usersTable}} WHERE email = ${email}`;
|
|
33
|
+
if (result.rows.length === 0) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const user = result.rows[0];
|
|
37
|
+
return {
|
|
38
|
+
id: user.id,
|
|
39
|
+
email: user.email,
|
|
40
|
+
name: user.name,
|
|
41
|
+
password: user.password,
|
|
42
|
+
created_at: user.created_at instanceof Date ? user.created_at.toISOString() : user.created_at,
|
|
43
|
+
updated_at: user.updated_at instanceof Date ? user.updated_at.toISOString() : user.updated_at
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export const updateUserPassword = async (email, newPassword, options) => {
|
|
47
|
+
const connectorName = options.connector.name;
|
|
48
|
+
const connector = await getConnector(connectorName);
|
|
49
|
+
const db = createDatabase(connector(options.connector.options));
|
|
50
|
+
const usersTable = options.tables.users;
|
|
51
|
+
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
52
|
+
await db.sql`
|
|
53
|
+
UPDATE {${usersTable}}
|
|
54
|
+
SET password = ${hashedPassword}, updated_at = CURRENT_TIMESTAMP
|
|
55
|
+
WHERE email = ${email}
|
|
56
|
+
`;
|
|
57
|
+
};
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default, type defaultOptions } from './module.mjs'
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nuxt-users",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Nuxt users module",
|
|
5
|
+
"repository": "rrd108/nuxt-users",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types.d.mts",
|
|
11
|
+
"import": "./dist/module.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/module.mjs",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
".": [
|
|
18
|
+
"./dist/types.d.mts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prepack": "nuxt-module-build build",
|
|
27
|
+
"predev": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
|
|
28
|
+
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
29
|
+
"dev:build": "nuxi build playground",
|
|
30
|
+
"dev:prepare": "yarn nuxt-module-build build --stub && yarn nuxt-module-build prepare && nuxi prepare playground",
|
|
31
|
+
"prerelease": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
|
|
32
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
33
|
+
"lint": "eslint .",
|
|
34
|
+
"lint:fix": "eslint . --fix",
|
|
35
|
+
"pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
|
|
36
|
+
"test": "yarn test:types && yarn test:sqlite && yarn test:mysql && yarn test:postgresql",
|
|
37
|
+
"test:watch": "vitest watch",
|
|
38
|
+
"test:sqlite": "./scripts/test-sqlite.sh",
|
|
39
|
+
"test:mysql": "./scripts/test-mysql.sh",
|
|
40
|
+
"test:postgresql": "./scripts/test-postgresql.sh",
|
|
41
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
|
|
42
|
+
"db:create-users-table": "tsx src/cli/create-users-table.ts",
|
|
43
|
+
"db:create-user": "tsx src/cli/create-user.ts",
|
|
44
|
+
"db:create-personal-access-tokens-table": "tsx src/cli/create-personal-access-tokens-table.ts",
|
|
45
|
+
"db:create-password-reset-tokens-table": "tsx src/cli/create-password-reset-tokens-table.ts",
|
|
46
|
+
"db:create-migrations-table": "tsx src/cli/create-migrations-table.ts",
|
|
47
|
+
"db:migrate": "tsx src/cli/migrate.ts",
|
|
48
|
+
"docs:dev": "vitepress dev docs",
|
|
49
|
+
"docs:build": "vitepress build docs",
|
|
50
|
+
"docs:preview": "vitepress preview docs"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@nuxt/kit": "^3.17.6",
|
|
54
|
+
"@types/bcrypt": "^5.0.2",
|
|
55
|
+
"@types/pg": "^8.15.4",
|
|
56
|
+
"bcrypt": "^6.0.0",
|
|
57
|
+
"better-sqlite3": "^12.2.0",
|
|
58
|
+
"defu": "^6.1.4",
|
|
59
|
+
"mysql2": "^3.14.2",
|
|
60
|
+
"nodemailer": "^7.0.5",
|
|
61
|
+
"pg": "^8.16.3",
|
|
62
|
+
"vitepress": "^1.6.3"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@formkit/nuxt": "^1.6.9",
|
|
66
|
+
"@nuxt/devtools": "^2.6.2",
|
|
67
|
+
"@nuxt/eslint-config": "^1.5.2",
|
|
68
|
+
"@nuxt/module-builder": "^1.0.1",
|
|
69
|
+
"@nuxt/schema": "^3.17.6",
|
|
70
|
+
"@nuxt/test-utils": "^3.19.2",
|
|
71
|
+
"@types/node": "latest",
|
|
72
|
+
"@types/nodemailer": "^6.4.17",
|
|
73
|
+
"changelogen": "^0.6.2",
|
|
74
|
+
"eslint": "^9.30.1",
|
|
75
|
+
"nuxt": "^3.17.6",
|
|
76
|
+
"ts-node": "^10.9.2",
|
|
77
|
+
"tsx": "^4.20.3",
|
|
78
|
+
"typescript": "~5.8.3",
|
|
79
|
+
"vitest": "^3.2.4",
|
|
80
|
+
"vue-tsc": "^3.0.1"
|
|
81
|
+
}
|
|
82
|
+
}
|