Skip to content

[Flutter] inviteUserByEmail() don't send metadata #1059

@daffypiwiit

Description

@daffypiwiit

Describe the bug
Hi, I'm not sure if it is a bug but when I try to send "data" into inviteUserByEmail, the request field userMetadata: {} stays empty.

To Reproduce
Steps to reproduce the behavior:
This is the code to invite user with metadata in flutter

 final UserResponse res = await supabase.client.auth.admin.inviteUserByEmail(
        '[email protected]',
        data: {
          'first_name': "test",
          'last_name': "one",
        },
      ); 

this is the empty request

"app_metadata": {
        "provider": "email",
        "providers": [
            "email"
        ]
    },
    "user_metadata": {},   //Empty
    "identities": [
        {
            "identity_id": "d5b8346f-8c9b-4a1e-a7df-XXX",
            "id": "954375bf-3687-4be0-83f2-XXX",
            "user_id": "XXX-3687-4be0-83f2-XXX",
            "identity_data": {
                "email": "[email protected]",
                "email_verified": false,
                "phone_verified": false,
                "sub": "954375bf-3687-4be0-83f2-XXXX"
}

Expected behavior
Send metadata in the request

userMetadata: {         
 'first_name': "test",
  'last_name': "one",
  } 

Possible Solution

I modify the function inviteUserByEmail() in .pub-cache/hosted/pub.dev/gotrue-2.10.0/lib/src/gotrue_admin_api.dart, and then it works the metadata was sent it successfully.

Future<UserResponse> inviteUserByEmail(
    String email, {
    String? redirectTo,
    Map<String, dynamic>? data,
  }) async {
    final body = {
      'email': email,
      if (data != null) 'data': data, //Add This and it works
    };
    final fetchOptions = GotrueRequestOptions(
      headers: _headers,
      body: body,
      redirectTo: redirectTo,
    );

    final response = await _fetch.request(
      '$_url/invite',
      RequestMethodType.post,
      options: fetchOptions,
    );
    return UserResponse.fromJson(response);
  }

Version (please complete the following information):
On Linux/macOS

├── supabase_auth_ui 0.5.2
│ └── supabase_flutter...
└── supabase_flutter 2.8.0
├── supabase 2.5.0
│ ├── functions_client 2.4.0
│ ├── gotrue 2.10.0
│ ├── postgrest 2.3.0
│ ├── realtime_client 2.4.0
│ ├── storage_client 2.2.0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    authThis issue or pull request is related to authenticationbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions