Composables
Authentication
Overview of the authentication with nuxt-directus.
Check out the Directus Authentication documentation.
Login
To login, you can use the login method from the useDirectusAuth composable that the module provides.
login.vue
<script setup>
const { login } = useDirectusAuth()
const handleSubmit = async () => {
await login('[email protected]', 'Passw0rd!')
}
</script>
Refresh tokens
To refresh the tokens, you can use the refresh method from the useDirectusAuth composable that the module provides.
If there is an refresh token in your cookie, no token needs to be specified for refreshing; the token is automatically used.
refresh-token.vue
<script setup>
const { refresh } = useDirectusAuth()
const handleRefreshToken = async () => {
await refresh()
}
</script>
Logout
To logout, you can use the logout method from the useDirectusAuth composable that the module provides.
You can provide a refreshToken to the logout method to revoke the token on the server. If no token is provided, the token is automatically taken from the state.
logout.vue
<script setup>
const { logout } = useDirectusAuth()
const handleLogout = async () => {
await logout()
}
</script>