useDirectusToken


You can use this composable to get the jwt token, it is used internally to get the directus_token cookie.

Currently, we have plans to add auto refresh token as an opt-in feature, but there is no ETA. More info Issue 56

refreshTokens

This composable function renews the token if you have a valid refesh_token in your cookie. The function will save the new token in the cookie if the renewal succeeds, if you don't need to manage the new token manually you can use the simple setup.

Return: DirectusAuthResponse

simple
<script setup>const { refreshTokens } = useDirectusToken();refreshTokens();</script>
manual
<script setup>const { refreshTokens } = useDirectusToken();const newToken = refreshTokens();</script>

token

You can use this composable to get the jwt token, it is used internally to get the directus_token cookie.

Return: string

<script setup>const { token } = useDirectusToken();const tokenString = token();</script>

refreshToken

this composable will return the token curretly save in your cookie, to refresh your token use refreshTokens

You can use this composable to get the jwt token, it is used internally to get the directus_token cookie.

Return: string

<script setup>const { token } = useDirectusToken();console.log(token());</script>

expires

You can use this composable to get the expire time of your token in a UNIX timestamp format.

Return: number

<script setup>const { expires } = useDirectusToken();console.log(expires());</script>