@wervt/cms 0.0.0 → 0.0.2
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 +2 -1
- package/dist/runtime/app/editor.vue +13 -3
- package/dist/runtime/server/access.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,7 +42,8 @@ characters.
|
|
|
42
42
|
`/_cms?key=<key>` is a small editor for one entry. `GET` and `PUT /api/_cms/entries/<key>` are
|
|
43
43
|
the API behind it; reading is public, saving needs an editor.
|
|
44
44
|
|
|
45
|
-
The app's owner, members and wervt admins can edit
|
|
45
|
+
The app's owner, members and wervt admins can edit, once signed in at `/_wervt/login` (the
|
|
46
|
+
editor links there; in `nuxt dev` it signs you in as the owner). To let others edit, list their addresses
|
|
46
47
|
(only confirmed ones count):
|
|
47
48
|
|
|
48
49
|
```ts [nuxt.config.ts]
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { ref, watch } from 'vue'
|
|
3
3
|
import { useFetch, useRoute } from '#app'
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const route = useRoute()
|
|
6
|
+
const key = String(route.query.key ?? 'home')
|
|
6
7
|
const { data } = await useFetch<{ value: Record<string, unknown> } | null>(
|
|
7
8
|
`/api/_cms/entries/${key}`,
|
|
8
9
|
)
|
|
@@ -11,13 +12,19 @@ watch(data, (entry) => (text.value = JSON.stringify(entry?.value ?? {}, null, 2)
|
|
|
11
12
|
immediate: true,
|
|
12
13
|
})
|
|
13
14
|
const status = ref('')
|
|
15
|
+
const signedOut = ref(false)
|
|
16
|
+
// A plain link, not a router navigation: on wervt the runtime answers this path, not the app.
|
|
17
|
+
const loginUrl = `/_wervt/login?redirect=${encodeURIComponent(route.fullPath)}`
|
|
14
18
|
|
|
15
19
|
async function save() {
|
|
20
|
+
signedOut.value = false
|
|
16
21
|
try {
|
|
17
22
|
await $fetch(`/api/_cms/entries/${key}`, { method: 'PUT', body: JSON.parse(text.value) })
|
|
18
23
|
status.value = 'Saved'
|
|
19
24
|
} catch (e) {
|
|
20
|
-
|
|
25
|
+
const error = e as { statusCode?: number; data?: { message?: string } }
|
|
26
|
+
signedOut.value = error.statusCode === 401
|
|
27
|
+
status.value = signedOut.value ? '' : (error.data?.message ?? String(e))
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
</script>
|
|
@@ -27,6 +34,9 @@ async function save() {
|
|
|
27
34
|
<h1>Content: {{ key }}</h1>
|
|
28
35
|
<textarea v-model="text" rows="12" style="width: 100%; font-family: monospace" />
|
|
29
36
|
<button type="button" @click="save">Save</button>
|
|
30
|
-
<p data-testid="status">
|
|
37
|
+
<p data-testid="status">
|
|
38
|
+
{{ status }}
|
|
39
|
+
<a v-if="signedOut" :href="loginUrl" data-testid="sign-in">Sign in to edit</a>
|
|
40
|
+
</p>
|
|
31
41
|
</main>
|
|
32
42
|
</template>
|
|
@@ -5,7 +5,7 @@ function requireEditor(event) {
|
|
|
5
5
|
const user = useWervtUser(event);
|
|
6
6
|
if (!user) throw createError({
|
|
7
7
|
status: 401,
|
|
8
|
-
message: "Sign in to edit"
|
|
8
|
+
message: "Sign in at /_wervt/login to edit"
|
|
9
9
|
});
|
|
10
10
|
if (user.role === "owner" || user.role === "member" || user.role === "admin" || user.admin) return user;
|
|
11
11
|
const config = useRuntimeConfig();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wervt/cms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Editable texts for Nuxt sites on wervt: written to a file in dev, to the app's database once deployed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@wervt/nuxt": "^0.3.
|
|
31
|
+
"@wervt/nuxt": "^0.3.23"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"drizzle-orm": "1.0.0-rc.5",
|