apstanisic / directus-dart

Directus SDK for Dart and Flutter
MIT License
37 stars 23 forks source link

Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index' #60

Closed bynicodevelop closed 1 year ago

bynicodevelop commented 1 year ago

Hello,

I'm testing Directus Flutter and I come across this error when creating a user :

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
#0      new DirectusResponse package:directus/…/data_classes/directus_response.dart:16
#1      DirectusResponse.fromRequest package:directus/…/data_classes/directus_response.dart:44

I'm on the version :

directus: ^0.7.2

I'm on the latest version of flutter: 3.3.8

My code is:

    final Directus sdk = await Directus(kEndpoint).init();

    final DirectusResponse<DirectusUser> response = await sdk.users.createOne(
      DirectusUser(
        email: "john@domain.tld",
        password: "password",
      ),
    );

In backend, i use the latest version of "directus-project" (self hosted).

Is it a user error on my part, or a problem on the side of the response object

bynicodevelop commented 1 year ago

I just found the beginning of an answer.

In the permissions to create a user, you must authorize in public:

Writing and reading.

The problem is that a user with the "public" role, shouldn't have read access.

Am I mistaken?

fracosfr commented 1 year ago

Hello,

Maybe an answer :

You can use the invite method await sdk.users.invite(email: 'test@example.com', role: 'some-uuid');

To secure you may create an user "signup user" with only the right to add user (you can use a custom right if you want), and create an unique token for this user.

And to create a new user, use a specific instance of the Directus Package with authentification by token with the "signup user" token.

If you dont want use the Directus interface, you can customize the link, but it seem this functionnality not yet available in the package.

apstanisic commented 1 year ago

I can't reproduce this error. But this is still a bug since Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index' should not be thrown exception. In my example it throws:

Unhandled exception:
Instance of 'DirectusError'
#0      DirectusResponse.fromRequest (package:directus_core/src/data_classes/directus_response.dart:46:7)

when I do not have sufficient permission

apstanisic commented 1 year ago

I think this is same as #39. Try 0.9.1. Reopen if exception still exists