Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Intevel/nuxt-directus
Browse files Browse the repository at this point in the history
  • Loading branch information
Intevel committed Jun 11, 2023
2 parents 19610b2 + 3cc1332 commit 77e1ff1
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 204 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## v5.4.3


### 🩹 Fixes

- UseRoute is undefined (1c95841)

### ❤️ Contributors

- Conner Bachmann ([@Intevel](http://github.com/Intevel))

## v5.4.2


### 🩹 Fixes

- Invalid url parsing (b7cba7a)
- UseDirectusUrl is not defined (3001e9b)

### ❤️ Contributors

- Conner Bachmann ([@Intevel](http://github.com/Intevel))

## v5.4.1


Expand Down
139 changes: 80 additions & 59 deletions docs/content/1.getting-started/2.options.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,80 @@
# Options

Configure Nuxt Directus easily with the `directus` property.

---

```ts [nuxt.config]
export default {
// Defaults options
directus: {
autoFetch: true,
}
}
```

## `url`

- No default - **Required**

The url to which requests are made to.

## `autoFetch`

- Default: `true`

Should the user be fetched automatically

## `fetchUserParams`

- No default - **Optional**

The Parameters which should be sent when the user is fetched, see [DirectusQueryParams](https://github.com/directus-community/nuxt-directus/blob/313a5a227e1d8b88a43d92c79b47a87d92a21fc5/src/runtime/types/index.d.ts#L26)

## `token`

- No default - **Optional**

A static token

## `cookieNameToken`

- Default: `directus_token`

Specify the cookie name of the directus auth token

## `cookieNameRefreshToken`

- Default: `directus_refresh_token`

Specify the cookie name of the directus refresh auth token

## `devtools`

- Default: `false`

Activate the Nuxt Devtools, checkout [Devtools](/getting-started/devtools) before activating

::feedback-box
::
# Options

Configure Nuxt Directus easily with the `directus` property.

---

```ts [nuxt.config]
export default {
// Defaults options
directus: {
autoFetch: true,
}
}
```

## `url`

- No default - **Required**

The url to which requests are made to.

## `autoFetch`

- Default: `true`

Should the user be fetched automatically

## `autoRefresh`

- Default: `true`

Auto refesh tokens


## `onAutoRefreshFailure()`

- Default: `not defined`

The function that get called if the `autoRefresh` fail

## `maxAgeRefreshToken`

- Default: `604800`

Need to be the same as specified in your directus config; this is the max amount of milliseconds that your refresh cookie will be kept in the browser.

Auto refesh tokens

## `fetchUserParams`

- No default - **Optional**

The Parameters which should be sent when the user is fetched, see [DirectusQueryParams](https://github.com/directus-community/nuxt-directus/blob/313a5a227e1d8b88a43d92c79b47a87d92a21fc5/src/runtime/types/index.d.ts#L26)

## `token`

- No default - **Optional**

A static token

## `cookieNameToken`

- Default: `directus_token`

Specify the cookie name of the directus auth token

## `cookieNameRefreshToken`

- Default: `directus_refresh_token`

Specify the cookie name of the directus refresh auth token

## `devtools`

- Default: `false`

Activate the Nuxt Devtools, checkout [Devtools](/getting-started/devtools) before activating

::feedback-box
::
26 changes: 1 addition & 25 deletions docs/content/2.composables/1.useDirectusAuth.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,7 @@ const onSubmit = async () => {

## Middleware example

### Redirect user to login

You can protect your authenticated routes by creating a custom middleware in your project, here is an example:

Create `./middleware/auth.ts`

```ts
export default defineNuxtRouteMiddleware((to, _from) => {
const user = useDirectusUser();

if (!user.value) {
return navigateTo("/login");
}
});
```

Now you can add the middleware to your pages

```ts
<script setup lang="ts">
definePageMeta({
middleware: ["auth"]
})
</script>
```
> Check how to Redirect user to login page [over here](/examples/redirectuserlogin).
::feedback-box
::
25 changes: 25 additions & 0 deletions docs/content/5.examples/1.useAsyncData.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# useAsyncData

---

Using `useAsyncData` composable allows your app to fetch data more efficiently with status control (pending, error) and the refresh function option.
Check [Nuxt 3 documentation](https://nuxt.com/docs/api/composables/use-async-data) for more details on `useAsyncData`

```js
const { getItemById } = useDirectusItems();

const {
data: myCollection,
pending,
error,
refresh,
} = await useAsyncData("myCollection", () =>
getItemById({
collection: myCollection,
id: id,
params: params,
})
);
```
::feedback-box
::
30 changes: 30 additions & 0 deletions docs/content/5.examples/2.redirectUserLogin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Redirect user to login

---

You can protect your authenticated routes by creating a custom middleware in your project, here is an example:

Create `./middleware/auth.ts`

```ts
export default defineNuxtRouteMiddleware((to, _from) => {
const user = useDirectusUser();

if (!user.value) {
return navigateTo("/login");
}
});
```

Now you can add the middleware to your pages

```ts
<script setup lang="ts">
definePageMeta({
middleware: ["auth"]
})
</script>
```

::feedback-box
::
2 changes: 2 additions & 0 deletions docs/content/5.examples/_dir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Examples
icon: heroicons-outline:chat-bubble-left-ellipsis
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-directus",
"version": "5.4.1",
"version": "5.4.3",
"license": "MIT",
"repository": "https://github.com/intevel/nuxt-directus",
"homepage": "https://nuxt-directus.netlify.app/",
Expand Down
Loading

1 comment on commit 77e1ff1

@vercel
Copy link

@vercel vercel bot commented on 77e1ff1 Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nuxt-directus – ./

nuxt-directus-docs.vercel.app
nuxt-directus-git-main-intevel.vercel.app
nuxt-directus-intevel.vercel.app

Please sign in to comment.