UNPKG

@userfrosting/sprinkle-account

Version:
66 lines (65 loc) 2.05 kB
import { watchEffect as m } from "vue"; import { u as y } from "./useAuthStore-DRHqdc4w.js"; function f(e) { const r = y(), s = () => e.currentRoute.value.meta.auth ?? null, l = () => e.currentRoute.value.meta.permission ?? null, o = () => e.currentRoute.value.meta.guest ?? null, h = () => { const t = s(); if (t !== null && !r.isAuthenticated) { const u = t.redirect ?? v(); a(u); } }, i = () => { const t = l(); if (r.isAuthenticated && (t == null ? void 0 : t.slug) !== void 0 && !r.checkAccess(t.slug)) { const u = t.redirect ?? n("Forbidden"); a(u); } }, p = () => { const t = o(); if (t !== null && r.isAuthenticated) { const u = R(t.redirect); a(u); } }, a = (t) => { e.replace(t); }, n = (t) => ({ name: t, params: { pathMatch: e.currentRoute.value.path.substring(1).split("/") }, query: e.currentRoute.value.query, hash: e.currentRoute.value.hash }), v = () => ({ name: "account.login", params: e.currentRoute.value.params, query: { ...e.currentRoute.value.query, redirect: e.currentRoute.value.path }, hash: e.currentRoute.value.hash }), R = (t) => { var u, c; if (((u = e.currentRoute.value.query) == null ? void 0 : u.redirect) !== void 0) { const d = (c = e.currentRoute.value.query.redirect) == null ? void 0 : c.toString(); return delete e.currentRoute.value.query.redirect, { path: d, params: e.currentRoute.value.params, query: e.currentRoute.value.query, hash: e.currentRoute.value.hash }; } else return t !== void 0 ? typeof t == "object" && t.name ? { name: t.name, params: e.currentRoute.value.params, query: e.currentRoute.value.query, hash: e.currentRoute.value.hash } : { path: t, params: e.currentRoute.value.params, query: e.currentRoute.value.query, hash: e.currentRoute.value.hash } : n("Unauthorized"); }; m(() => { h(), i(), p(); }); } export { f as u };