diff --git a/README.md b/README.md index 2ec734e..93bf1a0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ export default defineNuxtConfig({ // }, // registerComponents: true, // augmentContext: true, + // globalMiddleware: false, }, }) ``` @@ -63,17 +64,27 @@ Check out the [Hanko documentation](https://docs.hanko.io/guides/vue) to learn m ### Middleware -By default two new route middleware are available in your Nuxt app: `hanko-logged-in` and `hanko-logged-out`. +By default three new route middlewares are available in your Nuxt app: `hanko-logged-in`, `hanko-logged-out` and `hanko-allow-all`. - `hanko-logged-in` will prevent access to a page unless you are logged in. (It will redirect you to `redirects.login` instead, and then redirect back to this page once you login. You can disable this behaviour by setting `redirects.followRedirect` to `false`.) - `hanko-logged-out` will prevent access to a page unless you are logged out. (It will redirect you to `redirects.success` when you log in, and otherwise to `redirects.home`.) +- `hanko-allow-all` will allow all users access to page, even if the `globalMiddleware` option is set to `true`. (If the `globalMiddleware` option is not set to `true`, this middleware has no effect.) You can also create your own middleware for full control. +### Global Middleware + +If the `globalMiddleware` configuration is set to `true`, the middleware is automatically applied to all of your pages. +You can still override this behavior on each page, by applying the `hanko-logged-out` or the `hanko-allow-all` middleware. + +**Note**: The `globalMiddleware` option will not apply any authentication checks to your API-paths. + ### Auto-imports `useHanko` is exposed in the Vue part of your app to allow you direct access to the Hanko API. You can access the current user and much more. **Note**: It will return `null` on the server. +The `hankoLoggedIn` and `hankoLoggedOut` middleware are exposed to enable you to extend their functionality, such as creating a custom global middleware. + ### Server utilities By default you can access a verified JWT context on `event.context.hanko`. (It will be undefined if the user is not logged in.) If you want to handle this yourself you can set `augmentContext: false`. diff --git a/playground/pages/about.vue b/playground/pages/about.vue index c288fdb..c15f44a 100644 --- a/playground/pages/about.vue +++ b/playground/pages/about.vue @@ -1,3 +1,9 @@ + +