directus-dart
directus-dart copied to clipboard
How to get custom user fields?
I'm digging down a rabbit hole:
- Subclass DirectusUser to have a type with additional fields
- Add an extension to CurrentUser similar to read() readCustomUser() <- didn't really work
- Add a CustomUserConverter() <- can't inject this into CurrentUser.read
- 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.
I do not think there is a way to do it currently. Does Directus have support to adding custom fields in system tables?
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']);