Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a MatrixClient given a loginResponse #4633

Open
richvdh opened this issue Jan 20, 2025 · 0 comments
Open

How to create a MatrixClient given a loginResponse #4633

richvdh opened this issue Jan 20, 2025 · 0 comments
Labels
A-Documentation T-Task Tasks for the team like planning

Comments

@richvdh
Copy link
Member

richvdh commented Jan 20, 2025

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.

@dosubot dosubot bot added A-Documentation T-Task Tasks for the team like planning labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Documentation T-Task Tasks for the team like planning
Projects
None yet
Development

No branches or pull requests

1 participant