Skip to content
Back

Unable to send team invitation in flutter

  • 1
  • Teams
  • Flutter
HiMaNameIs
25 Dec, 2023, 15:44

here's my code :

TypeScript
  void inviteToBecomeManager(User user) async{
    await client_aw.Teams(ClientDatabase.client!).createMembership(
      teamId: 'managers',
      roles: [''],
      email: user.email,
      userId: user.$id,
      phone: user.phone,
      name: user.name,
      url: '$link?projectId=$project&endpoint=$endpoint}'
    ).then((value) {
      f.showDialog(
          barrierDismissible: true,
          context: current, builder: (co){
        return const Text('invitationsent').tr();
      });
    }).onError((client_aw.AppwriteException error, stackTrace) {
      if(kDebugMode){
        print('====================================================');
        print('error sending invitation');
        print('type: ${error.type}');
        print('code: ${error.code}');
        print('message: ${error.message}');
        print('response: ${error.response}');
        print('stacktrace: $stackTrace');
        print('====================================================');

      }
    });
  }

and the error

TypeScript
type: user_unauthorized
code: 401
message: User is not allowed to send invitations for this team
 response: {message: User is not allowed to send invitations for this team, code: 401, type: user_unauthorized, version: 0.12.20}
stacktrace: #0      ClientMixin.prepareResponse (package:appwrite/src/client_mixin.dart:73:9)
#1      ClientIO.call (package:appwrite/src/client_io.dart:373:14)
<asynchronous suspension>
#2      Teams.createMembership (package:appwrite/services/teams.dart:187:17)
<asynchronous suspension>
#3      UsersManagementDatasource.inviteToBecomeManager.<anonymous closure> (package:parc_oto/datasources/user_management/user_datasource.dart:138:12)
<asynchronous suspension>
#4      UsersManagementDatasource.inviteToBecomeManager (package:parc_oto/datasources/user_management/user_datasource.dart:130:5)
<asynchronous suspension>

The account is sent the invitation with is the creator of the team, and a member

TL;DR
The user encountered an error while trying to send a team invitation using Flutter. The error message indicates that the user is unauthorized to send invitations for the team. The code provided in the post shows the `inviteToBecomeManager` function used to send the invitation. Solution: The user needs to ensure that the account creating the invitation has the `owner` role for the team. This can be verified in the code or in the server-side function `teams.updateMembership()`. Additionally, the user mentioned creating the team using a cloud appwrite and not within the app itself, which may be causing the authorization issue.
ideclon
25 Dec, 2023, 17:54

Does the account creating the invite have the owner role on the Team?

HiMaNameIs
25 Dec, 2023, 18:00

Well, i created the team using cloud appwrite, not in app Can i simply add "owner" as a label ?

ideclon
25 Dec, 2023, 18:06

Not from the Console. But you could use the server side teams.updateMembership() function

HiMaNameIs
25 Dec, 2023, 18:08

Yes that one works fine Alright, i'll just have to create the teams in-app from now on I thought a team member can invite other members Thanks for the help, and happy holidays

HiMaNameIs
25 Dec, 2023, 18:45

Btw, you can also do it in the console, but you need to remove your user account from the team , then add it back with "owner" as a role

ideclon
25 Dec, 2023, 19:05

Yes, but that requires recreating the Membership

HiMaNameIs
25 Dec, 2023, 19:06

Yeah it's true, in my case, since i only use specefic roles, i don't care much about membership id

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more