Hello @jsharl error 401 is Unauthorized, means that you don’t have the permission to ban other users, you will have to be an admin. Another way for admin to ban users is via the console, please see the attached image below. If you have further questions, pls let us know
We tried everything regarding ban/unban or even mute/unmute but it seems like we can’t manage to make it work.
Everything I get is a 401 or a 404 in some cases.
For each channel we create, we want to be able to promote one or more members as moderator(s).
A moderator should be able to ban / unban (or mute / unmute ) basic members.
We want a former moderator for each room , and this moderator should be able to promote other members as moderator from the front-end of the app.
We don’t want the moderator to be global, but only for one room.
Hi @jsharl since this action is not supported by our sdk as I mentioned above. Thus, I have double checked with the team for other possible ways, and yes, we do have a workaround to achieve this.
You can check for user role in your front-end first if they’re moderator or not. If yes, then you can call the ban user API using the hardcode admin access token. However, I would suggest you to build a ban API on your backend and inside that API, you can call Amity ban user API with the hardcode admin access token as it’s more secure and there’s no need for frontend update
You can check for user role in your front-end first if they’re moderator or not. If yes, then you can call the ban user API using the hardcode admin access token
Actually, this is what we are currently doing and talking about.
Function that gets the Amity token given a userId:
(This request is triggered at app launch)
export const getAmityToken: any = createAsyncThunk(
'officialChatRoom/getAmityToken',
async (userId, thunk) => {
const result = await amityTokenRequest(`/api/v3/authentication/token?userId=${userId}`, 'get');
return result.data;
// The result is stored in the local storage
// Then a function called getAmityToken retrieves it (see base request above)
}
);
Request from RTK :
(I guess the issue is somewhere here in the process… am I getting the good token ?)
export const banMember: any = createAsyncThunk(
'officialChatRoom/banMember',
async (data, thunk) => {
const { channelId, body } = data;
const result = await amityRequest(body, `/api/v3/channel/${channelId}/users/ban`, 'put');
return result;
}
);
Action called from the component after interaction:
Hi @jsharl just to double confirm if you get the correct Admin access token that we mentioned, we’re referring to Amity’s console admin access token which you can generate from going to asc.amity.co
Log in → Settings → Admin Users → Click on setting icon in admin user
and there will be a popup, then click on Generate access token. You can hardcode this admin access token and use it when calling ban user API