oneeach
Request response not updated
Try this:
const { data, execute: getBook } = await useFetch('https://mysite.local/api/books', {
lazy: true,
server: false,
immediate: false,
watch: false,
credentials: "include",
onResponse({ response }) {
console.log(response._data)
}
});
4 replies
Middleare for Auth
no, it's not normal. The middleware should run before you can see the page. Where are you putting your middleware? Can you recreate your middleware here: https://nuxt.new/s/v3
21 replies
Middleare for Auth
it's also good practice to throw an error to notify users they are trying to access an unauthorized page with something like this in your middleware:
if (!localStorage.getItem('loggedIn')) {
throw createError({ statusCode: 403, statusMessage: 'Unauthorized' })
}
21 replies
Middleare for Auth
you would need to make your middleware global to apply to all pages or you can define which middleware applies to a specific page by adding it to your PageMeta:
definePageMeta({
middleware: 'auth'
})
If you go with the global method, you would then need to specify which routes are accessible to users not logged in with something like this:
definePageMeta({
auth: false,
})
To make middleware global, just append 'global.ts' to the filename. like auth.global.ts
21 replies
Init new Nuxt project without "Initialize git repository" check?
npx nuxi init frontend --packageManager yarn --git-init=false
https://nuxt.com/docs/api/commands/init#options3 replies
Dynamic Sitemap Generation not working in production
have you tired to use an async function to get your urls?
https://nuxtseo.com/sitemap/getting-started/data-sources#_1-build-time-provide-a-urls-function
61 replies