Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module): add auth.populate option for fetchUser #260

Merged
merged 3 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/content/2.setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ Cookie options of the Strapi token cookie `strapi_jwt`.

> All cookie options can be found in the [Nuxt documentation](https://v3.nuxtjs.org/docs/usage/cookies/#options)

### `auth.populate`

::div{.inline-flex .items-center .gap-3}
::badge
v1.5.0+
::

::badge
Strapi v4.2.2+
::
::

Configure the `populate` query param of the `/users/me` route.

> Learn more on [Populating documentation](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/entity-service/populate.html#advanced-populating).

## Edge channel

To use the latest updates pushed on the [`dev`](https://github.com/nuxt-community/strapi-module/tree/dev) branch, you can use `@nuxtjs/strapi-edge`.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const user = await fetchUser()
</script>
```

> Learn how to override the default [`/users/me` route behaviour](/advanced#override-strapi-usersme-route) in your Strapi application.
> Learn how to populate relations in [`/users/me` route](/setup#authpopulate).

## `useStrapi{3|4}`

Expand Down
4 changes: 4 additions & 0 deletions docs/content/4.advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export default defineNuxtPlugin((nuxt) => {

## 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.
::

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.

Here is how to override this method for both Strapi v3 and v4 by adding our own custom relation, in this example `restaurants`:
Expand Down
Loading