I wrote a script to see if revoking a user token results in an error. And half of the time it will return the correct 401 unauthorized error and the other half of the time it will succeed in sending the message.
let messageCount = 0;
const serverClient = StreamChat.getInstance(env.GETSTREAM_APP_IDENTIFIER, env.GETSTREAM_API_KEY);
async function sendMessage(channel: Channel<DefaultGenerics>) {
try {
await channel.sendMessage({ text: `This is message test ${messageCount++}` });
console.log(`sent a message`);
} catch (error) {
console.error(error);
}
}
async function testRevoke() {
const userId = 'revoke_test';
const userId2 = 'other_user_test';
const issuedAt = Math.floor(Date.now() / 1000);
const token = serverClient.createToken(userId, undefined, issuedAt);
const client = StreamChat.getInstance(env.GETSTREAM_APP_IDENTIFIER);
client.connectUser({ id: userId }, token);
const channel = await client.channel('messaging', {
members: [userId, userId2],
});
await channel.create();
await sendMessage(channel);
const tokenResponse = await client.revokeUserToken(userId1);
console.log(tokenResponse);
// do I need to wait after revoking the token?
setTimeout(async () => {
await sendMessage(channel);
client.disconnectUser();
}, 5000);
}
the token response has revoke_tokens_issued_before
I know the token should be created server side but just for the sake of the script I'm doing it inline here. In the actual app it is hitting a server for the token.
Do I need to wait a certain time before calls know about the token being revoked?
I wrote a script to see if revoking a user token results in an error. And half of the time it will return the correct 401 unauthorized error and the other half of the time it will succeed in sending the message.
the token response has
revoke_tokens_issued_before
I know the token should be created server side but just for the sake of the script I'm doing it inline here. In the actual app it is hitting a server for the token.
Do I need to wait a certain time before calls know about the token being revoked?