Skip to content

Instantly share code, notes, and snippets.

@cardoso
Last active October 17, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cardoso/7b9f5af60d3861ea53482e3ab6a795a9 to your computer and use it in GitHub Desktop.
Save cardoso/7b9f5af60d3861ea53482e3ab6a795a9 to your computer and use it in GitHub Desktop.
import chatClient from "./chatClient";
export default async (id, keyPair) => {
const response = await chatClient.setUser(
{
id,
name: id,
image: `https://getstream.io/random_png/?id=cool-recipe-9&name=${id}`,
},
chatClient.devToken(id)
);
if (
response.me?.publicKeyJwk &&
response.me.publicKeyJwk != JSON.stringify(keyPair.publicKeyJwk)
) {
await chatClient.disconnect();
throw "This user id already exists with a different key pair. Choose a new user id or paste the correct key pair.";
}
await chatClient.upsertUsers([
{ id, publicKeyJwk: JSON.stringify(keyPair.publicKeyJwk) },
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment