supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
719 stars 173 forks source link

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

Closed daffypiwiit closed 1 week ago

daffypiwiit commented 1 week ago

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(
        'test@test.com',
        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": "test@test.com",
                "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.

dshukertjr commented 1 week ago

Thanks for reporting this. Would you like to submit a PR for the fix?

daffypiwiit commented 1 week ago

Thanks for reporting this. Would you like to submit a PR for the fix?

Yes Sure, this is the PR

https://github.com/supabase/supabase-flutter/pull/1061

dshukertjr commented 1 week ago

Thank you so much for the awesome work!

daffypiwiit commented 6 days ago

Thank you so much for the awesome work!

Thank you, Supabase it's an excellent product!