matrix-org / matrix-org/matrix-js-sdk
How to create a `MatrixClient` given a `loginResponse`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.2k
- Forks
- 704
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 40
Description
Previously, creating a MatrixClient for a newly-logged-in user looked something like this:
const hs = "https://matrix.org/";
const loginClient = sdk.createClient({ baseUrl: hs });
const loginResponse = await client.loginRequest({
type: "m.login.password",
identifier: { type: "m.id.user", user: "userid" },
password: "mysecretpassword",
});
// Create a new matrix client
const matrixClient = sdk.createClient({
baseUrl: loginResponse.well_known?.["m.homeserver"] ?? hs,
accessToken: loginResponse.access_token,
userId: loginResponse.user_id,
deviceId: loginResponse.device_id,
});
Even that is subtle enough, and totally undocumented. However, I believe that, since MSC2918 support was added, it is no longer adequate, and I don't know what the right way to do it is. Is the tokenRefreshFunction required? If so, what do I set it to?
Worse, what little documentation there is (in the README) is wrong, since it omits things not only the refresh token, but things like deviceId.
This could really do with updating. We should probably have a utility function to make it easy.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README's client-creation documentation and the sdk.createClient/loginRequest entry points shown in the issue. Determine the supported construction from loginResponse, including token refresh behavior and deviceId, then update the documentation so a newcomer can create a working client without guesswork.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, authentication, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100