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

How to get custom user fields? #56

Open
DigNZ opened this issue Aug 16, 2022 · 2 comments
Open

How to get custom user fields? #56

DigNZ opened this issue Aug 16, 2022 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@DigNZ
Copy link

DigNZ commented Aug 16, 2022

I'm digging down a rabbit hole:

  1. Subclass DirectusUser to have a type with additional fields
  2. Add an extension to CurrentUser similar to read() readCustomUser() <- didn't really work
  3. Add a CustomUserConverter() <- can't inject this into CurrentUser.read
  4. Implement the client call directly and skip the currentUser accessor <- works but seems smelly.

Is there a way to get a user object with custom fields? If not there should be. If yes can it be documented please.

@apstanisic
Copy link
Owner

I do not think there is a way to do it currently. Does Directus have support to adding custom fields in system tables?

@apstanisic apstanisic added the enhancement New feature or request label Aug 22, 2022
@apstanisic
Copy link
Owner

apstanisic commented Jan 9, 2023

For 3 option, it is possible to customize converter with sdk.users.converter = MyConverter();. Only make sure that return value extends DirectusUser or Dart will throw an exception.

Hi, I played around a little, and this is simplest solution I could think off.
I know it's not ideal, if anybody has time I am open to more proper solutions.

  final sdk = await getSdk();
  final user = DirectusUser(
      email: "[email protected]",
      password: "password",
// this values are same as columns, they should not be camel cased
      rawValues: {"test_value": "RawValue"});
  final res = await sdk.users.createOne(user);
  print(res.data.rawValues['test_value']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants