4

How to get users' own data from a collection?

After a successful login, /auth/login does not return user-related info except the Bearer token.

So how do I request only the logged-in users' data from a collection?

While using GraphQL I can filter my result by this way if I knew my user ID. But I don't think it's the best way.

(filter:{user_created:{id:{_eq: "59d5bc57-6a67-4200-b435-553403c5b503"} }})

vinyll
  • 11,017
  • 2
  • 48
  • 37
Cem Kaan
  • 2,086
  • 1
  • 24
  • 55

2 Answers2

2

It's in the docs. :)

https://docs.directus.io/reference/api/system/users/?#retrieve-the-current-user

The endpoint "${api_url}/users/me" will return the information for the currently authenticated user. You should be able to map this to GQL as you need.

titusfx
  • 1,896
  • 27
  • 36
Shea Lavington
  • 436
  • 2
  • 7
0

Directus allows you to call the current user via the GraphQL query to /graphql/system:

query me {
    users_me {
        id
    }
}

This retrieves the id and you can add the fields you need.

It is compatible with the Directus SDK if you're using it.

vinyll
  • 11,017
  • 2
  • 48
  • 37