1.2.16 • Published 1 year ago
nuxt-directus-auth v1.2.16
Nuxt Directus Auth
A Nuxt 3 module to handle Directus authentication
Features
- Support for Universal and SPA Nuxt 3 applications
- Implements Directus authentication through
useDirectusAuth
- Auto refresh of access token through
useDirectusFetch
- Route middleware auth protection
- Typescript support
- Lightweight only 14kb
Installation
npm i nuxt-directus-auth
Setup
Add nuxt-directus-auth
to your nuxt modules and set directusAuth
options
export default defineNuxtConfig({
//...
modules: ["nuxt-directus-auth"],
directusAuth: {
baseUrl: "http://localhost:8055", // Directus API base url
nuxtBaseUrl: "http://localhost:3000", // Nuxt app base url
enableGlobalAuthMiddleware: false, // Enable auth middleware on every page
refreshTokenCookieName: "directus_refresh_token", // Directus refresh token cookie name (optional)
defaultRoleId: "", // Role id assigned for registered users
redirect: {
login: "/auth/login", // Path to redirect when login is required
logout: "/auth/login", // Path to redirect after logout
home: "/home", // Path to redirect after successful login
resetPassword: "/auth/reset-password", // Path to redirect for password reset
},
},
//...
});
Usage
For protecting routes, 2 possible configuration can be used
- Globally enable and locally disable
enableGlobalAuthMiddleware: true;
definePageMeta({ auth: false })
- Locally enable
definePageMeta({ middleware: "auth" }) // Redirects to login path when not loggedIn
definePageMeta({ middleware: "guest" }) // Redirects to home path when loggedIn
Appendix
Development
- Run
npm run dev:prepare
to generate type stubs. - Use
npm run dev
to start playground in development mode.
1.2.16
1 year ago
1.2.15
1 year ago
1.2.14
1 year ago
1.2.13
1 year ago
1.2.12
1 year ago
1.2.11
1 year ago
1.2.10
1 year ago
1.2.9
1 year ago
1.2.8
1 year ago
1.2.7
1 year ago
1.1.7
1 year ago
1.1.6
1 year ago
1.1.5
1 year ago
1.1.4
1 year ago
1.1.3
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.1.0
1 year ago
1.0.8
1 year ago
1.0.7
1 year ago
1.0.6
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago