nuxt-auto-crud 1.6.0 → 1.8.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/dist/module.json
CHANGED
|
@@ -2,35 +2,28 @@ import { eq } from "drizzle-orm";
|
|
|
2
2
|
import { useDrizzle } from "#site/drizzle";
|
|
3
3
|
import * as tables from "#site/schema";
|
|
4
4
|
import { useAutoCrudConfig } from "../utils/config.js";
|
|
5
|
-
import { defineNitroPlugin } from "#imports";
|
|
5
|
+
import { defineNitroPlugin, hashPassword, onHubReady } from "#imports";
|
|
6
6
|
export default defineNitroPlugin(async () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
30
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
31
|
-
});
|
|
32
|
-
console.log("Admin user seeded.");
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
7
|
+
onHubReady(async () => {
|
|
8
|
+
const { auth } = useAutoCrudConfig();
|
|
9
|
+
if (!auth?.authentication || !tables.users) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const db = useDrizzle();
|
|
13
|
+
const existingAdmin = await db.select().from(tables.users).where(eq(tables.users.email, "admin@example.com")).get();
|
|
14
|
+
if (!existingAdmin) {
|
|
15
|
+
console.log("Seeding admin user...");
|
|
16
|
+
const hashedPassword = await hashPassword("$1Password");
|
|
17
|
+
await db.insert(tables.users).values({
|
|
18
|
+
email: "admin@example.com",
|
|
19
|
+
password: hashedPassword,
|
|
20
|
+
name: "Admin User",
|
|
21
|
+
avatar: "https://i.pravatar.cc/150?u=admin",
|
|
22
|
+
role: "admin",
|
|
23
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
24
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
25
|
+
});
|
|
26
|
+
console.log("Admin user seeded.");
|
|
27
|
+
}
|
|
28
|
+
});
|
|
36
29
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createError } from "h3";
|
|
2
|
+
import { requireUserSession } from "#imports";
|
|
2
3
|
import { useAutoCrudConfig } from "./config.js";
|
|
3
4
|
import { verifyJwtToken } from "./jwt.js";
|
|
4
5
|
export async function checkAdminAccess(event, model, action) {
|
|
@@ -13,9 +14,6 @@ export async function checkAdminAccess(event, model, action) {
|
|
|
13
14
|
}
|
|
14
15
|
return verifyJwtToken(event, auth.jwtSecret);
|
|
15
16
|
}
|
|
16
|
-
if (typeof requireUserSession !== "function") {
|
|
17
|
-
throw new TypeError("requireUserSession is not available");
|
|
18
|
-
}
|
|
19
17
|
try {
|
|
20
18
|
await requireUserSession(event);
|
|
21
19
|
if (auth.authorization) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auto-crud",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Exposes RESTful CRUD APIs for your Nuxt app based solely on your database migrations.",
|
|
5
5
|
"author": "Cliford Pereira",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"jose": "^5.9.6"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"drizzle-orm": "
|
|
58
|
+
"drizzle-orm": ">=0.30.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@iconify-json/heroicons": "^1.2.3",
|
|
@@ -5,51 +5,37 @@ import { useDrizzle } from '#site/drizzle'
|
|
|
5
5
|
import * as tables from '#site/schema'
|
|
6
6
|
import { useAutoCrudConfig } from '../utils/config'
|
|
7
7
|
// @ts-expect-error - #imports is available in runtime
|
|
8
|
-
import { defineNitroPlugin } from '#imports'
|
|
8
|
+
import { defineNitroPlugin, hashPassword, onHubReady } from '#imports'
|
|
9
9
|
|
|
10
10
|
export default defineNitroPlugin(async () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// @ts-expect-error - onHubReady is auto-imported from @nuxthub/core
|
|
14
|
-
onHubReady(async () => {
|
|
15
|
-
const { auth } = useAutoCrudConfig()
|
|
11
|
+
onHubReady(async () => {
|
|
12
|
+
const { auth } = useAutoCrudConfig()
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
// Only seed if auth is enabled and we have a users table
|
|
15
|
+
if (!auth?.authentication || !tables.users) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
const db = useDrizzle()
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
// Check if admin exists
|
|
22
|
+
const existingAdmin = await db.select().from(tables.users).where(eq(tables.users.email, 'admin@example.com')).get()
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Use hashPassword from nuxt-auth-utils if available, otherwise simple mock or error
|
|
30
|
-
// Since we can't guarantee nuxt-auth-utils is present in module context, we try to use it dynamically or assume it's there
|
|
31
|
-
// But wait, the module depends on nuxt-auth-utils being present in the user project for auth to work.
|
|
24
|
+
if (!existingAdmin) {
|
|
25
|
+
console.log('Seeding admin user...')
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
// @ts-expect-error - hashPassword is auto-imported
|
|
36
|
-
hashedPassword = await hashPassword('$1Password')
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
console.warn('hashPassword not available, using plain text (insecure)')
|
|
40
|
-
}
|
|
27
|
+
const hashedPassword = await hashPassword('$1Password')
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
29
|
+
await db.insert(tables.users).values({
|
|
30
|
+
email: 'admin@example.com',
|
|
31
|
+
password: hashedPassword,
|
|
32
|
+
name: 'Admin User',
|
|
33
|
+
avatar: 'https://i.pravatar.cc/150?u=admin',
|
|
34
|
+
role: 'admin',
|
|
35
|
+
createdAt: new Date(),
|
|
36
|
+
updatedAt: new Date(),
|
|
37
|
+
})
|
|
38
|
+
console.log('Admin user seeded.')
|
|
39
|
+
}
|
|
40
|
+
})
|
|
55
41
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { H3Event } from 'h3'
|
|
2
2
|
import { createError } from 'h3'
|
|
3
|
+
// @ts-expect-error - #imports is available in runtime
|
|
4
|
+
import { requireUserSession } from '#imports'
|
|
3
5
|
import { useAutoCrudConfig } from './config'
|
|
4
6
|
import { verifyJwtToken } from './jwt'
|
|
5
7
|
|
|
@@ -19,13 +21,7 @@ export async function checkAdminAccess(event: H3Event, model: string, action: st
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
// Session based (default)
|
|
22
|
-
// @ts-expect-error - requireUserSession is auto-imported
|
|
23
|
-
if (typeof requireUserSession !== 'function') {
|
|
24
|
-
throw new TypeError('requireUserSession is not available')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
24
|
try {
|
|
28
|
-
// @ts-expect-error - requireUserSession is auto-imported
|
|
29
25
|
await requireUserSession(event)
|
|
30
26
|
|
|
31
27
|
// Check authorization if enabled
|
|
@@ -49,7 +45,7 @@ export async function checkAdminAccess(event: H3Event, model: string, action: st
|
|
|
49
45
|
if ((e as any).statusCode === 403) {
|
|
50
46
|
throw e
|
|
51
47
|
}
|
|
52
|
-
// Otherwise (401 from requireUserSession), return false (treat as guest)
|
|
48
|
+
// Otherwise (401 from requireUserSession or function not available), return false (treat as guest)
|
|
53
49
|
return false
|
|
54
50
|
}
|
|
55
51
|
}
|