scaffold blog_portal vue 3 + pinia + cypress frontend
Mirrors youngstartup/frontend/startups_portal scaffolding: Vite, Vue 3 (composition API + script setup), TypeScript strict, Pinia, Vue Router 5, oxlint + eslint + oxfmt, and Cypress with db:reset / db:seed tasks. Views and the auth store are stubs filled in by the next branches; routes and the header chrome are wired so the build passes.
This commit is contained in:
parent
6f95a5b7b8
commit
568dc4aabe
27 changed files with 8376 additions and 0 deletions
83
frontend/blog_portal/src/router/index.ts
Normal file
83
frontend/blog_portal/src/router/index.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import HomePage from "@/views/HomePage.vue";
|
||||
import LoginPage from "@/views/LoginPage.vue";
|
||||
import SignupPage from "@/views/SignupPage.vue";
|
||||
import CheckEmailPage from "@/views/CheckEmailPage.vue";
|
||||
import ConfirmEmailPage from "@/views/ConfirmEmailPage.vue";
|
||||
import ProfilePage from "@/views/ProfilePage.vue";
|
||||
import PostPage from "@/views/PostPage.vue";
|
||||
import NewPostPage from "@/views/NewPostPage.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{ path: "/", name: "home", component: HomePage },
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: LoginPage,
|
||||
beforeEnter: requireGuest,
|
||||
},
|
||||
{
|
||||
path: "/signup",
|
||||
name: "signup",
|
||||
component: SignupPage,
|
||||
beforeEnter: requireGuest,
|
||||
},
|
||||
{
|
||||
path: "/check-email",
|
||||
name: "check-email",
|
||||
component: CheckEmailPage,
|
||||
},
|
||||
{
|
||||
path: "/confirm-email",
|
||||
name: "confirm-email",
|
||||
component: ConfirmEmailPage,
|
||||
beforeEnter: (to) => {
|
||||
if (!to.query.token) return { name: "login" };
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/users/:displayName",
|
||||
name: "profile",
|
||||
component: ProfilePage,
|
||||
props: true,
|
||||
},
|
||||
{
|
||||
path: "/users/:displayName/posts/new",
|
||||
name: "new-post",
|
||||
component: NewPostPage,
|
||||
props: true,
|
||||
beforeEnter: requireAuth,
|
||||
},
|
||||
{
|
||||
path: "/posts/:id",
|
||||
name: "post",
|
||||
component: PostPage,
|
||||
props: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
router.beforeEach(async () => {
|
||||
const auth = useAuthStore();
|
||||
if (!auth.checked) {
|
||||
await auth.fetchMe();
|
||||
}
|
||||
auth.clearError();
|
||||
});
|
||||
|
||||
async function requireGuest() {
|
||||
const auth = useAuthStore();
|
||||
if (!auth.checked) await auth.fetchMe();
|
||||
if (auth.user) return { name: "home" };
|
||||
}
|
||||
|
||||
async function requireAuth() {
|
||||
const auth = useAuthStore();
|
||||
if (!auth.checked) await auth.fetchMe();
|
||||
if (!auth.user) return { name: "login" };
|
||||
}
|
||||
|
||||
export default router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue