Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Jan 23, 2023
1 parent 00b7915 commit b1d4ecf
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

> [Strapi](https://strapi.io) module for Nuxt.
- [ Release Notes](https://github.com/nuxt-community/strapi-module/releases)
- [ Release Notes](https://github.com/nuxt-modules/strapi/releases)
- [📖  Read the documentation](https://strapi.nuxtjs.org)

## Features
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cta:
- /setup
secondary:
- Star on GitHub →
- https://github.com/nuxt-community/strapi-module
- https://github.com/nuxt-modules/strapi
snippet: yarn add -D @nuxtjs/strapi
---

Expand Down
10 changes: 5 additions & 5 deletions docs/content/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Depending on which version you have in your [options](/setup#options), you will
::alert{type="info"}
All examples below are demonstrated with v4 `useStrapi()`. :br
:br
Note that v3 exposes the same methods with different options. Check out specific types for [v3](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v3.d.ts) and [v4](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v4.d.ts).
Note that v3 exposes the same methods with different options. Check out specific types for [v3](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v3.d.ts) and [v4](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts).
::

> Learn how to handle Strapi errors globally by using [nuxt hooks](/advanced#errors-handling).
Expand Down Expand Up @@ -46,7 +46,7 @@ Get entries. Returns entries matching the query filters (see [parameters](https:

- **Arguments:**
- contentType: `string`
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v4.d.ts#L24)
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24)
- **Returns:** `Promise<T>`

```vue
Expand All @@ -68,7 +68,7 @@ Returns an entry by `id`.
- **Arguments:**
- contentType: `string`
- id?: `string | number | Strapi4RequestParams`
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v4.d.ts#L24)
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24)
- **Returns:** `Promise<T>`

```vue
Expand Down Expand Up @@ -179,7 +179,7 @@ Available only for `v3` as Strapi v4 can do the same thing with the [Pagination

- **Arguments:**
- contentType: `string`
- params?: [`Strapi3RequestParams`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v3.d.ts#L9)
- params?: [`Strapi3RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v3.d.ts#L9)
- **Returns:** `Promise<number>`

```vue
Expand All @@ -198,7 +198,7 @@ This composable is an alias of `useStrapiClient` that sets the `url` to `/graphq

- **Arguments:**
- query: `string|DocumentNode`
- variables (optional): [`StrapiGraphqlVariables`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L555)
- variables (optional): [`StrapiGraphqlVariables`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L570)
- **Returns:** `Promise<T>`

```vue
Expand Down
66 changes: 45 additions & 21 deletions docs/content/4.auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ const token = useStrapiToken()
This composable exposes all the methods available in the Strapi [Users & Permissions plugin](https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html).

::alert{type="info"}
On `login`, `register`, `resetPassword` and `authenticateProvider` methods, the user is populated through the [`fetchUser`](/usage#fetchuser) method.
On `login`, `register`, `resetPassword` and `authenticateProvider` methods, the user is populated through the [`fetchUser`](/auth#fetchuser) method.
::

### `login`

Submit the user's identifier and password credentials for authentication. Sets [`user`](/usage#useStrapiUser) and [`token`](/usage#useStrapiToken).
Submit the user's identifier and password credentials for authentication. Sets [`user`](/auth#usestrapiuser) and [`token`](/auth#usestrapitoken).

- **Arguments:**
- data: [`StrapiAuthenticationData`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L529)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L524)
- data: [`StrapiAuthenticationData`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L538)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L533)

```vue [pages/login.vue]
<script setup lang="ts">
Expand All @@ -58,7 +58,7 @@ const onSubmit = async () => {
### `logout`

Unset [`user`](/usage#useStrapiUser) and [`token`](/usage#useStrapiToken).
Unset [`user`](/auth#usestrapiuser) and [`token`](/auth#usestrapitoken).

```vue
<script setup lang="ts">
Expand All @@ -80,8 +80,8 @@ Creates a new user in the database with a default role as `Authenticated`.
Custom user fields, if added to the content type, e.g. `phoneNumber`, can be added to the payload as well.

- **Arguments:**
- data: [`StrapiRegistrationData`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L534)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L524)
- data: [`StrapiRegistrationData`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L543)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L533)

```vue [pages/register.vue]
<script setup lang="ts">
Expand All @@ -102,10 +102,10 @@ const onSubmit = async () => {
### `forgotPassword`

This action sends an email to a user with the link to your own reset password page. The link will be enriched with the url param code that is needed for the [`resetPassword`](/usage#resetPassword).
This action sends an email to a user with the link to your own reset password page. The link will be enriched with the url param code that is needed for the [`resetPassword`](/auth#resetpassword).

- **Arguments:**
- data: [`StrapiForgotPasswordData`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L541)
- data: [`StrapiForgotPasswordData`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L550)
- **Returns:** `Promise<void>`

```vue [pages/forgot.vue]
Expand All @@ -123,15 +123,15 @@ const onSubmit = async () => {
</script>
```

> Check out the Strapi [Forgotten & reset password](https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#forgotten-reset-password) documentation.
> Check out the Strapi [Forgot & Reset flow](https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#reset-password) documentation.
### `resetPassword`

This action will update the user password. Sets [`user`](/usage#useStrapiUser) and [`token`](/usage#useStrapiToken).
This action will update the user password. Sets [`user`](/auth#usestrapiuser) and [`token`](/auth#usestrapitoken).

- **Arguments:**
- data: [`StrapiResetPasswordData`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L545)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L524)
- data: [`StrapiResetPasswordData`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L554)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L533)

```vue [pages/reset.vue]
<script setup lang="ts">
Expand All @@ -148,14 +148,38 @@ const onSubmit = async () => {
</script>
```

> Check out the Strapi [Forgotten & reset password](https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#forgotten-reset-password) documentation.
> Check out the Strapi [Forgot & Reset flow](https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#reset-password) documentation.
### `changePassword`

You can also update an authenticated user password through the `/change-password` API endpoint:

- **Arguments:**
- data: [`StrapiChangePasswordData`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L560)
- **Returns:** `Promise<void>`

```vue
<script setup lang="ts">
const { changePassword } = useStrapiAuth()
const onSubmit = async () => {
try {
await changePassword({ currentPassword: '', password: '', passwordConfirmation: '' })
$toast.success('Password changed!')
} catch (e) {}
}
</script>
```

> Check out the Strapi [Change password flow](https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#reset-password) documentation.
### `sendEmailConfirmation`

This action will re-send the confirmation sent after [`registration`](/usage#register).
This action will re-send the confirmation sent after [`registration`](/auth#register).

- **Arguments:**
- data: [`StrapiEmailConfirmationData`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L551)
- data: [`StrapiEmailConfirmationData`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L566)
- **Returns:** `Promise<void>`

```vue
Expand All @@ -179,7 +203,7 @@ const onSubmit = async () => {
Return the correct URL to authenticate with provider.

- **Arguments:**
- provider: [`StrapiAuthProvider`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L505)
- provider: [`StrapiAuthProvider`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L505)
- **Returns:** `string`

```vue [pages/login.vue]
Expand All @@ -194,12 +218,12 @@ const onClick = () => {

### `authenticateProvider`

Authenticate user with external provider. Sets [`user`](/usage#useStrapiUser) and [`token`](/usage#useStrapiToken).
Authenticate user with external provider. Sets [`user`](/auth#usestrapiuser) and [`token`](/auth#usestrapitoken).

- **Arguments:**
- provider: [`StrapiAuthProvider`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L505)
- provider: [`StrapiAuthProvider`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L505)
- access_token: `string`
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/index.d.ts#L524)
- **Returns:** [`Promise<StrapiAuthenticationResponse>`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/index.d.ts#L533)

```vue [pages/auth/[provider]/callback.vue]
<script setup lang="ts">
Expand All @@ -212,7 +236,7 @@ await authenticateProvider('github', route.query.access_token)

### `fetchUser`

Fetch `me` user from `/users/me` route if a [`token`](/usage#useStrapiToken) exists in the cookies then sets [`user`](/usage#useStrapiUser).
Fetch `me` user from `/users/me` route if a [`token`](/auth#usestrapitoken) exists in the cookies then sets [`user`](/auth#usestrapiuser).

::alert{type="info"}
This method is called on the server-side only and the data are hydrated client-side so the HTTP call happens only once. This method is called by default on init through a [Nuxt plugin](https://nuxt.com/docs/guide/directory-structure/plugins), so you don't have to.
Expand Down
8 changes: 4 additions & 4 deletions docs/content/5.advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default defineNuxtPlugin((nuxt) => {
})
```

> Check out the [Strapi4Error](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v4.d.ts#L3) type.
> Check out the [Strapi4Error](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L3) type.
### `v3`

Expand All @@ -112,12 +112,12 @@ export default defineNuxtPlugin((nuxt) => {
})
```

> Check out the [Strapi3Error](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/types/v3.d.ts#L3) type.
> Check out the [Strapi3Error](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v3.d.ts#L3) type.
## Override Strapi `/users/me` route

::alert
Since [v1.5.0](https://github.com/nuxt-community/strapi-module/releases/tag/v1.5.0) and Strapi [v4.2.2](https://github.com/strapi/strapi/releases/tag/v4.2.2), you can use the [`auth.populate`](/setup#authpopulate) option to populate data from `/users/me` route.
Since [v1.5.0](https://github.com/nuxt-modules/strapi/releases/tag/v1.5.0) and Strapi [v4.2.2](https://github.com/strapi/strapi/releases/tag/v4.2.2), you can use the [`auth.populate`](/setup#authpopulate) option to populate data from `/users/me` route.
::

By default, when calling `/users/me` route, Strapi only returns the user populated with the role. Strapi `User.me` controller from the `users-permissions` plugin returns the `ctx.state.user` populated by the `fetchAuthenticated` method.
Expand Down Expand Up @@ -180,7 +180,7 @@ async function onSubmit () {
</script>
```

> Note that you have to use the `client` because `create` and `update` methods sends the [body inside `data`](https://github.com/nuxt-community/strapi-module/blob/dev/src/runtime/composables/useStrapi4.ts#L64).
> Note that you have to use the `client` because `create` and `update` methods sends the [body inside `data`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/composables/useStrapi4.ts#L64).
## Use Imported GraphQL

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nuxtjs/strapi",
"version": "1.7.0",
"description": "Strapi module for Nuxt",
"repository": "nuxt-community/strapi-module",
"repository": "nuxt-modules/strapi",
"license": "MIT",
"exports": {
".": {
Expand Down

0 comments on commit b1d4ecf

Please sign in to comment.