useDirectusUsers


If you are looking to get data for the current login user, check out the Directus useDirectusUser documentation.

getUsers

Search for users, global search querys can be used

Arguments: (optional)

Returns:

JavaScript
<script setup>const { getUsers } = useDirectusUsers();const users = await getUsers();</script>
TypeScript
<script setup lang="ts">const { getUsers } = useDirectusUsers();import { DirectusUser } from "nuxt-directus/dist/runtime/types";const users = await getUsers<DirectusUser[]>();</script>
with Parameters
<script setup>const { getUsers } = useDirectusUsers();import { DirectusUser } from "nuxt-directus/dist/runtime/types";const filters = {  last_name: "Jefferson",  first_name: "Thomas",};const users = await getUsers<DirectusUser[]>({  params: {    filter: filters,  },});</script>

getUserById

Search for a user by id

Arguments:

Returns:

JavaScript
<script setup>const { getUserById } = useDirectusUsers();const user = await getUserById({  id: "1",});</script>
TypeScript
<script setup>import { DirectusUser } from "nuxt-directus/dist/runtime/types";const {getUserById} = useDirectusUsers();const user = await getUserById<DirectusUser>({  id: "1",});</script>

createUsers

Create one or multiple users

Arguments:

Returns: Array<T>

JavaScript
<script setup>const { createUsers } = useDirectusUsers();const user = await createUsers({  // ... user object or array of user});</script>
TypeScript
<script setup>import { DirectusUser } from "nuxt-directus/dist/runtime/types";const {createUsers} = useDirectusUsers();const user = await createUsers<DirectusUser>({  // ... user object or array of user});</script>

deleteUsers

Delete one or multiple users

  • Arguments:
    • data:
multiple (array)
{  users: [      '4776864a-75ee-4746-9ef4-bd5c2e38cc66',      '4776864a-75ee-4746-9ef4-bd5c2e38cc67',      '4776864a-75ee-4746-9ef4-bd5c2e38cc68'      ];}
single (string)
{  users:"4776864a-75ee-4746-9ef4-bd5c2e38cc66";}
  • Returns: Empty body
JavaScript
<script setup>const { deleteUsers } = useDirectusUsers();const user = await deleteUsers({  users: ["4776864a-75ee-4746-9ef4-bd5c2e38cc66"],});</script>

updateUser

Update user

Arguments:

Returns: Array<T>

JavaScript
<script setup>const { updateUser } = useDirectusUsers();const user = await updateUser({  id: "1",  user:{    // DirectusUser    first_name: 'Abraham',    last_name: 'Lincoln',    location: 'Hodgenville, KY'}});</script>
TypeScript
<script setup>import { DirectusUser } from "nuxt-directus/dist/runtime/types";const { updateUser } = useDirectusUsers();const user = await updateUser<DirectusUser>({  id: "1",  user:{    // DirectusUser    first_name: 'Abraham',    last_name: 'Lincoln',    location: 'Hodgenville, KY'  }});</script>