diff --git a/src/auth/auth.composable.js b/src/auth/auth.composable.js index e8a5f62..df4432b 100644 --- a/src/auth/auth.composable.js +++ b/src/auth/auth.composable.js @@ -37,21 +37,22 @@ export function useAuth() { const canUserWrite = computed( () => payload.value && canWrite(payload.value, "other", "mink-app") ); + /** Indicates whether a jwt request is currently loading. */ const isAuthenticating = computed(() => pending.value.includes("jwt")); /** If not authenticated, redirect to the login page. */ async function requireAuthentication(callback) { + // First, ensure the jwt has been fetched. if (!jwt.value) { await refreshJwt(); } + // If still no jwt, it means the user hasn't authenticated. Show our login page. if (!jwt.value) { + // By passing current page as destination param, the user will then be redirected back to where they first attempted to go. router.push(`/login?destination=${route.fullPath}`); return; } - if (!canUserWrite.value) { - router.push("/access-denied"); - return; - } + // When calling `requireAuthentication`, you can optionally specify what should happen upon success. callback?.(); }