Give the job tracker stores and fix the admin route guard
createCrudStore captures the places store's pattern and now backs places, job applications and job references. JobApplications.vue no longer calls gql() itself and is split into the applications table, the references table and the add form, with the status vocabulary in jobStatus.js. api.js is a thin REST client that turns failures into an ApiError carrying the backend's message; the admin views and Listening.vue use it in place of raw axios and fetch. The router guard waited on the home query's loaded flag, which is never set when that query fails, so /admin and /cv/jobs could hang. It now awaits a standalone me query owned by the auth store, and homeData gains a settled flag for widgets that only need to know the fetch finished. The Vite proxy targets are configurable through VITE_PROXY_*, and build:js runs the Vite build without wasm-pack. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+13
-23
@@ -13,11 +13,9 @@
|
||||
*/
|
||||
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import { watch } from "vue";
|
||||
import DefaultLayout from "@/layouts/DefaultLayout.vue";
|
||||
import CVLayout from "@/layouts/CVLayout.vue";
|
||||
import Landing from "@/views/landing/Landing.vue";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const router = createRouter({
|
||||
@@ -120,29 +118,21 @@ const router = createRouter({
|
||||
|
||||
// Guard for routes marked `meta: { requiresAdmin: true }`.
|
||||
//
|
||||
// The admin flag comes from homeData's `me` field, which arrives asynchronously.
|
||||
// Navigating straight to /admin on a cold load would otherwise read an empty
|
||||
// user and bounce a legitimate admin to the login page, so the guard first
|
||||
// blocks on homeData.loaded. The watcher is self-stopping: `stop()` is called
|
||||
// from inside the callback before resolving, so the promise settles exactly
|
||||
// once and the watcher does not leak across navigations.
|
||||
// The admin flag arrives asynchronously, so navigating straight to /admin on a
|
||||
// cold load would otherwise read an empty user and bounce a legitimate admin to
|
||||
// the login page. The guard therefore awaits auth.ensureLoaded(), which issues
|
||||
// a standalone `me` query unless the user is already known.
|
||||
//
|
||||
// It deliberately does not wait on the home query (stores/homeData.js): that
|
||||
// one fans out to Spotify, Steam and Gitea, and a guard that waited on it hung
|
||||
// forever when it failed. ensureLoaded() always settles — a failed `me` reads
|
||||
// as "not signed in" — and `user` is re-read on every navigation, so a login or
|
||||
// logout during the session is honoured.
|
||||
router.beforeEach(async (to) => {
|
||||
if (!to.meta.requiresAdmin) return;
|
||||
const homeData = useHomeDataStore();
|
||||
if (!homeData.loaded) {
|
||||
await new Promise((resolve) => {
|
||||
const stop = watch(
|
||||
() => homeData.loaded,
|
||||
(val) => {
|
||||
if (val) {
|
||||
stop();
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
if (!useAuthStore().user.admin)
|
||||
const auth = useAuthStore();
|
||||
await auth.ensureLoaded();
|
||||
if (!auth.user.admin)
|
||||
return { path: "/admin/login", query: { redirect: to.fullPath } };
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user