few shots update
This commit is contained in:
@@ -37,22 +37,19 @@
|
||||
@DATA_CONTRACT: Input[$props.requiredPermission?: string|null, $props.fallbackPath?: string] -> Output[UIState{isCheckingAccess:boolean, hasRouteAccess:boolean}]
|
||||
-->
|
||||
|
||||
<script lang="ts">
|
||||
<script>
|
||||
import { onMount } from "svelte";
|
||||
import { auth } from "../../lib/auth/store";
|
||||
import { api } from "../../lib/api";
|
||||
import { goto } from "$app/navigation";
|
||||
import { hasPermission } from "$lib/auth/permissions.js";
|
||||
|
||||
const { requiredPermission = null, fallbackPath = "/profile" } = $props<{
|
||||
requiredPermission?: string | null;
|
||||
fallbackPath?: string;
|
||||
}>();
|
||||
const { requiredPermission = null, fallbackPath = "/profile", children } = $props();
|
||||
|
||||
let hasRouteAccess = $state(false);
|
||||
let isCheckingAccess = $state(true);
|
||||
|
||||
const belief_scope = async <T>(scopeId: string, run: () => Promise<T>): Promise<T> => {
|
||||
const belief_scope = async (scopeId, run) => {
|
||||
console.info(`[${scopeId}][REASON] belief_scope.enter`);
|
||||
try {
|
||||
return await run();
|
||||
@@ -61,7 +58,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
<!-- [DEF:verifySessionAndAccess:Function] -->
|
||||
// [DEF:verifySessionAndAccess:Function]
|
||||
/**
|
||||
* @PURPOSE: Validates session and optional permission gate before allowing protected content render.
|
||||
* @PRE: auth store is initialized and can provide token/user state; navigation is available.
|
||||
@@ -69,7 +66,7 @@
|
||||
* @SIDE_EFFECT: Mutates auth loading/user state, performs API I/O to /auth/me, and may redirect.
|
||||
* @DATA_CONTRACT: Input[AuthState, requiredPermission, fallbackPath] -> Output[RouteDecision{login_redirect|fallback_redirect|grant}]
|
||||
*/
|
||||
async function verifySessionAndAccess(): Promise<void> {
|
||||
async function verifySessionAndAccess() {
|
||||
return belief_scope("ProtectedRoute.verifySessionAndAccess", async () => {
|
||||
console.info("[ProtectedRoute.verifySessionAndAccess][REASON] Starting route access verification");
|
||||
isCheckingAccess = true;
|
||||
@@ -128,7 +125,7 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
<!-- [/DEF:verifySessionAndAccess:Function] -->
|
||||
// [/DEF:verifySessionAndAccess:Function]
|
||||
|
||||
onMount(() => {
|
||||
void verifySessionAndAccess();
|
||||
@@ -140,7 +137,7 @@
|
||||
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
||||
</div>
|
||||
{:else if $auth.isAuthenticated && hasRouteAccess}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
{/if}
|
||||
|
||||
<!-- [/DEF:ProtectedRoute:Component] -->
|
||||
|
||||
Reference in New Issue
Block a user