Scaffold Docwell monorepo with PocketBase authentication
Phase 0 foundation for Docwell, an open-source knowledge base: - Database: PocketBase v0.40.6 with initial schema migrations; users is the built-in auth collection, plus a hook for token checks and env-driven app URL/SMTP settings - Server: Go API (health, version, auth endpoints forwarded to PocketBase, admin user list) with an embedded Vue admin panel - Web-App: Go static server and Vue/Tailwind app with Tiptap editor, sign-in, sign-up, password reset and email verification (EN/PL) - Desktop-App: Wails v3 host reusing the web app - Phone-App: Flutter app with sign-in - Shared packages (editor, ui, api-client), OpenAPI spec, Docker compose (separate services and all-in-one), GitHub Actions CI - Docs: feature inventory and architecture/build plan Licensed under AGPL-3.0-or-later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
4903bb12dd
264 files changed
+21422
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { useTheme } from "@docwell/ui";
|
||||
import { useRouter } from "vue-router";
|
||||
import { currentUser, signOut } from "./session";
|
||||
|
||||
useTheme();
|
||||
const router = useRouter();
|
||||
|
||||
const nav = [
|
||||
{ to: "/", label: "Overview" },
|
||||
{ to: "/users", label: "Users" },
|
||||
{ to: "/workspaces", label: "Workspaces" },
|
||||
{ to: "/authentication", label: "Authentication" },
|
||||
{ to: "/storage", label: "Storage" },
|
||||
{ to: "/email", label: "Email" },
|
||||
{ to: "/maintenance", label: "Maintenance" },
|
||||
];
|
||||
|
||||
function logout() {
|
||||
signOut();
|
||||
router.replace({ name: "login" });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterView v-if="!currentUser" />
|
||||
<div v-else class="flex min-h-dvh flex-col md:flex-row">
|
||||
<aside class="flex flex-col border-b border-border bg-surface-muted md:w-56 md:border-r md:border-b-0">
|
||||
<div class="px-4 py-3 font-semibold">Docwell Admin</div>
|
||||
<nav class="flex gap-1 overflow-x-auto px-2 pb-2 text-sm md:flex-1 md:flex-col">
|
||||
<RouterLink
|
||||
v-for="item in nav"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
class="rounded-md px-3 py-1.5 whitespace-nowrap hover:bg-surface"
|
||||
exact-active-class="bg-surface font-medium"
|
||||
>
|
||||
{{ item.label }}
|
||||
</RouterLink>
|
||||
</nav>
|
||||
<div class="hidden border-t border-border p-3 text-sm md:block">
|
||||
<div class="truncate font-medium">{{ currentUser.name }}</div>
|
||||
<div class="truncate text-xs text-fg-muted">{{ currentUser.email }}</div>
|
||||
<button class="mt-2 text-xs text-fg-muted hover:text-fg" @click="logout">Sign out</button>
|
||||
</div>
|
||||
</aside>
|
||||
<main class="flex-1 p-4 sm:p-8">
|
||||
<RouterView />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
import { createApp } from "vue";
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import App from "./App.vue";
|
||||
import { currentUser, restoreSession } from "./session";
|
||||
import "./style.css";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory("/admin/"),
|
||||
routes: [
|
||||
{ path: "/login", name: "login", component: () => import("./views/LoginView.vue"), meta: { public: true } },
|
||||
{ path: "/", name: "overview", component: () => import("./views/OverviewView.vue") },
|
||||
{ path: "/users", name: "users", component: () => import("./views/UsersView.vue") },
|
||||
{ path: "/workspaces", name: "workspaces", component: () => import("./views/PlaceholderView.vue"), meta: { title: "Workspaces" } },
|
||||
{ path: "/authentication", name: "authentication", component: () => import("./views/PlaceholderView.vue"), meta: { title: "Authentication" } },
|
||||
{ path: "/storage", name: "storage", component: () => import("./views/PlaceholderView.vue"), meta: { title: "Storage" } },
|
||||
{ path: "/email", name: "email", component: () => import("./views/PlaceholderView.vue"), meta: { title: "Email" } },
|
||||
{ path: "/maintenance", name: "maintenance", component: () => import("./views/PlaceholderView.vue"), meta: { title: "Maintenance" } },
|
||||
],
|
||||
});
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
await restoreSession();
|
||||
if (!to.meta.public && !currentUser.value) return { name: "login", query: { redirect: to.fullPath } };
|
||||
if (to.name === "login" && currentUser.value) return { name: "overview" };
|
||||
});
|
||||
|
||||
createApp(App).use(router).mount("#app");
|
||||
@@ -0,0 +1,44 @@
|
||||
import { ApiError, createClient, createTokenStore, type User } from "@docwell/api-client";
|
||||
import { ref } from "vue";
|
||||
|
||||
// The admin panel is served by docwell-server itself, so the API is same-origin.
|
||||
const tokens = createTokenStore("docwell.admin.token");
|
||||
|
||||
export const currentUser = ref<User | null>(null);
|
||||
let restored = false;
|
||||
|
||||
export const api = createClient({
|
||||
baseUrl: "",
|
||||
token: tokens.get,
|
||||
onUnauthorized: () => signOut(),
|
||||
});
|
||||
|
||||
/** Signs in and keeps the session only for instance admins. */
|
||||
export async function signIn(email: string, password: string) {
|
||||
const session = await api.auth.login(email, password);
|
||||
if (!session.user.isAdmin) {
|
||||
throw new ApiError(403, { error: "forbidden" });
|
||||
}
|
||||
tokens.set(session.token);
|
||||
currentUser.value = session.user;
|
||||
}
|
||||
|
||||
export function signOut() {
|
||||
tokens.set(null);
|
||||
currentUser.value = null;
|
||||
}
|
||||
|
||||
/** Restores a saved admin session once per page load. */
|
||||
export async function restoreSession() {
|
||||
if (restored) return;
|
||||
restored = true;
|
||||
if (!tokens.get()) return;
|
||||
try {
|
||||
const session = await api.auth.refresh();
|
||||
if (!session.user.isAdmin) throw new Error("not an admin");
|
||||
tokens.set(session.token);
|
||||
currentUser.value = session.user;
|
||||
} catch {
|
||||
signOut();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@import "tailwindcss";
|
||||
@import "@docwell/ui/theme.css";
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import { ApiError } from "@docwell/api-client";
|
||||
import { DwButton } from "@docwell/ui";
|
||||
import { ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { signIn } from "../session";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const email = ref("");
|
||||
const password = ref("");
|
||||
const error = ref("");
|
||||
const busy = ref(false);
|
||||
|
||||
const messages: Record<string, string> = {
|
||||
invalid_credentials: "Wrong email or password.",
|
||||
forbidden: "This account is not an instance admin.",
|
||||
account_disabled: "This account is disabled.",
|
||||
mfa_required: "This account uses two-step sign-in. Sign in to the web app first; MFA for the admin panel is not supported yet.",
|
||||
};
|
||||
|
||||
async function submit() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
await signIn(email.value, password.value);
|
||||
const redirect = typeof route.query.redirect === "string" && route.query.redirect.startsWith("/") ? route.query.redirect : "/";
|
||||
router.replace(redirect);
|
||||
} catch (e) {
|
||||
error.value = e instanceof ApiError ? (messages[e.code] ?? "Sign-in failed.") : "Can't reach the server.";
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid min-h-dvh place-items-center bg-surface-muted px-4">
|
||||
<form class="w-full max-w-sm space-y-4 rounded-xl border border-border bg-surface p-6 shadow-sm" @submit.prevent="submit">
|
||||
<h1 class="text-xl font-semibold">Docwell Admin</h1>
|
||||
<p class="text-sm text-fg-muted">Sign in with an instance admin account.</p>
|
||||
<label class="block space-y-1 text-sm">
|
||||
<span class="font-medium">Email</span>
|
||||
<input v-model="email" type="email" autocomplete="email" required class="w-full rounded-md border border-border bg-surface px-3 py-2 outline-none focus:border-brand-500" />
|
||||
</label>
|
||||
<label class="block space-y-1 text-sm">
|
||||
<span class="font-medium">Password</span>
|
||||
<input v-model="password" type="password" autocomplete="current-password" required class="w-full rounded-md border border-border bg-surface px-3 py-2 outline-none focus:border-brand-500" />
|
||||
</label>
|
||||
<p v-if="error" role="alert" class="text-sm text-red-600">{{ error }}</p>
|
||||
<DwButton type="submit" class="w-full justify-center" :disabled="busy">Sign in</DwButton>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { ApiError, type Status, type Version } from "@docwell/api-client";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { api } from "../session";
|
||||
|
||||
const version = ref<Version | null>(null);
|
||||
const readiness = ref<Status | null>(null);
|
||||
const userCount = ref<number | null>(null);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
version.value = await api.version();
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
try {
|
||||
readiness.value = await api.readiness();
|
||||
} catch (e) {
|
||||
readiness.value = e instanceof ApiError ? (e.body as Status) : { status: "unavailable" };
|
||||
}
|
||||
userCount.value = await api.admin
|
||||
.listUsers({ perPage: 1 })
|
||||
.then((l) => l.totalItems)
|
||||
.catch(() => null);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1 class="text-xl font-semibold">Overview</h1>
|
||||
<p v-if="error" class="mt-4 text-sm text-red-600">{{ error }}</p>
|
||||
<div class="mt-6 grid gap-4 sm:grid-cols-3">
|
||||
<div class="rounded-lg border border-border p-4">
|
||||
<div class="text-xs text-fg-muted">Server version</div>
|
||||
<div class="mt-1 text-lg font-medium">{{ version?.version ?? "…" }}</div>
|
||||
</div>
|
||||
<div class="rounded-lg border border-border p-4">
|
||||
<div class="text-xs text-fg-muted">Database</div>
|
||||
<div
|
||||
class="mt-1 text-lg font-medium"
|
||||
:class="readiness?.status === 'ok' ? 'text-emerald-600' : readiness ? 'text-red-600' : ''"
|
||||
>
|
||||
{{ readiness ? (readiness.status === "ok" ? "Connected" : "Unavailable") : "…" }}
|
||||
</div>
|
||||
</div>
|
||||
<RouterLink to="/users" class="rounded-lg border border-border p-4 hover:bg-surface-muted">
|
||||
<div class="text-xs text-fg-muted">Users</div>
|
||||
<div class="mt-1 text-lg font-medium" data-testid="user-count">{{ userCount ?? "…" }}</div>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,4 @@
|
||||
<template>
|
||||
<h1 class="text-xl font-semibold">{{ $route.meta.title }}</h1>
|
||||
<p class="mt-2 text-sm text-fg-muted">Not built yet. See docs/PLAN.md, section 8.</p>
|
||||
</template>
|
||||
@@ -0,0 +1,78 @@
|
||||
<script setup lang="ts">
|
||||
import type { UserList } from "@docwell/api-client";
|
||||
import { onMounted, ref, watch } from "vue";
|
||||
import { api } from "../session";
|
||||
|
||||
const perPage = 20;
|
||||
const page = ref(1);
|
||||
const search = ref("");
|
||||
const list = ref<UserList | null>(null);
|
||||
const error = ref("");
|
||||
|
||||
async function load() {
|
||||
error.value = "";
|
||||
try {
|
||||
list.value = await api.admin.listUsers({ page: page.value, perPage, q: search.value });
|
||||
} catch {
|
||||
error.value = "Could not load users.";
|
||||
}
|
||||
}
|
||||
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
watch(search, () => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
page.value = 1;
|
||||
load();
|
||||
}, 250);
|
||||
});
|
||||
watch(page, load);
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<h1 class="text-xl font-semibold">Users</h1>
|
||||
<input
|
||||
v-model="search"
|
||||
type="search"
|
||||
placeholder="Search name or email"
|
||||
class="w-full rounded-md border border-border bg-surface px-3 py-1.5 text-sm outline-none focus:border-brand-500 sm:w-64"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="error" role="alert" class="mt-4 text-sm text-red-600">{{ error }}</p>
|
||||
|
||||
<div class="mt-6 overflow-x-auto rounded-lg border border-border">
|
||||
<table class="w-full text-left text-sm">
|
||||
<thead class="bg-surface-muted text-xs text-fg-muted">
|
||||
<tr>
|
||||
<th class="px-4 py-2 font-medium">Name</th>
|
||||
<th class="px-4 py-2 font-medium">Email</th>
|
||||
<th class="px-4 py-2 font-medium">Role</th>
|
||||
<th class="px-4 py-2 font-medium">Status</th>
|
||||
<th class="px-4 py-2 font-medium">Verified</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="u in list?.items" :key="u.id" class="border-t border-border">
|
||||
<td class="px-4 py-2 font-medium">{{ u.name }}</td>
|
||||
<td class="px-4 py-2">{{ u.email }}</td>
|
||||
<td class="px-4 py-2">{{ u.isAdmin ? "Admin" : "User" }}</td>
|
||||
<td class="px-4 py-2 capitalize">{{ u.status }}</td>
|
||||
<td class="px-4 py-2">{{ u.verified ? "Yes" : "No" }}</td>
|
||||
</tr>
|
||||
<tr v-if="list && list.items.length === 0">
|
||||
<td colspan="5" class="px-4 py-6 text-center text-fg-muted">No users found.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div v-if="list && list.totalItems > perPage" class="mt-4 flex items-center gap-3 text-sm">
|
||||
<button class="rounded border border-border px-2 py-1 disabled:opacity-40" :disabled="page <= 1" @click="page--">Previous</button>
|
||||
<span class="text-fg-muted">Page {{ page }} of {{ Math.ceil(list.totalItems / perPage) }}</span>
|
||||
<button class="rounded border border-border px-2 py-1 disabled:opacity-40" :disabled="page * perPage >= list.totalItems" @click="page++">
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user