Repository navigation
What is the proper way to use pinia-colada in Nuxt middleware? #587
Answered
by
posva
akfakf0509
asked this question in
Questions
|
Hello. When writing logic such as login or permission checks, I would like to reuse However, Nuxt middleware is a bit different. At first, using So I am currently trying the following approach. Is this an appropriate usage pattern? export default defineNuxtRouteMiddleware(async () => {
const queryCache = useQueryCahce();
const queryOptions = getSomeQueryOptions(...);
const cache = queryCache.getQueryData(queryOptions.key);
let ok = cache?.ok;
if (typeof ok !== "boolean") {
const entry = queryCache.ensure(queryOptions);
const res = await queryCache.fetch(entry);
if (res.status !== "success") throw createError({ status: 500, fatal: true });
ok = res.data.ok;
queryCache.setQueryData(queryOptions.key, res.data);
}
if (!ok) throw createError({ status: 401, fatal: true });
});Or am I overthinking this? Would it be acceptable to just use |
Answered by
posva
May 14, 2026
Replies: 1 comment
|
Yes, using defined options and the cache is the way. UseQuery is only for reactivity |
0 replies
Answer selected by
akfakf0509
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, using defined options and the cache is the way. UseQuery is only for reactivity