Compose authentication, authorization, and graceful session-expiry behavior with minimal app glue code.
export default defineNuxtConfig({
modules: ['better-convex-nuxt'],
convex: {
url: process.env.CONVEX_URL,
auth: {
enabled: true,
routeProtection: {
redirectTo: '/auth/signin',
preserveReturnTo: true,
},
unauthorized: {
enabled: true,
redirectTo: '/auth/signin',
includeQueries: false, // start conservative
},
},
permissions: true,
},
})
definePageMeta({
convexAuth: true,
})
<script setup lang="ts">
const { can, pending } = usePermissions()
const canEdit = can('post.update')
</script>
<template>
<button v-if="!pending && canEdit">Edit Post</button>
</template>
includeQueries: false) to avoid noisy background redirects.includeQueries: true if you want the same deduped unauthorized recovery flow for queries.