Skip to content

Commit 5c7e60d

Browse files
committed
MatrixClient.login no longer stashes the returned access token
Previously, `MatrixClient.login` had some very unintuitive behaviour where it stashed the access token, but not the device id, refresh token, etc etc, which led people to imagine that they had a functional MatrixClient when they didn't. Ideally we would stash all the returned credentials so that the app doesn't need to make a new MatrixClient, but that's a bit complicated (especially with OIDC) and more than I have time for, so let's at least disable the footgun by not saving *anything*. Fixes: #4502
1 parent a6fd28b commit 5c7e60d

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/client.ts

+17-20
Original file line numberDiff line numberDiff line change
@@ -8244,29 +8244,23 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
82448244
}
82458245

82468246
/**
8247-
* @returns Promise which resolves to a LoginResponse object
8248-
* @returns Rejects: with an error response.
8247+
* Sends a `/login` request to the server, to create a new device.
8248+
*
8249+
* Note that the results are *not* persisted in this {@link MatrixClient} object: a new `MatrixClient`
8250+
* must be constructed to use the returned details.
82498251
*/
82508252
public login(loginType: LoginRequest["type"], data: Omit<LoginRequest, "type">): Promise<LoginResponse> {
8251-
return this.http
8252-
.authedRequest<LoginResponse>(Method.Post, "/login", undefined, {
8253-
...data,
8254-
type: loginType,
8255-
})
8256-
.then((response) => {
8257-
if (response.access_token && response.user_id) {
8258-
this.http.opts.accessToken = response.access_token;
8259-
this.credentials = {
8260-
userId: response.user_id,
8261-
};
8262-
}
8263-
return response;
8264-
});
8253+
return this.http.authedRequest<LoginResponse>(Method.Post, "/login", undefined, {
8254+
...data,
8255+
type: loginType,
8256+
});
82658257
}
82668258

82678259
/**
8268-
* @returns Promise which resolves to a LoginResponse object
8269-
* @returns Rejects: with an error response.
8260+
* Sends a `/login` request to the server with username and password, to create a new device.
8261+
*
8262+
* Note that the results are *not* persisted in this {@link MatrixClient} object: a new `MatrixClient`
8263+
* must be constructed to use the returned details.
82708264
*/
82718265
public loginWithPassword(user: string, password: string): Promise<LoginResponse> {
82728266
return this.login("m.login.password", {
@@ -8308,9 +8302,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
83088302
}
83098303

83108304
/**
8305+
* Sends a `/login` request to the server with login token, to create a new device.
8306+
*
8307+
* Note that the results are *not* persisted in this {@link MatrixClient} object: a new `MatrixClient`
8308+
* must be constructed to use the returned details.
8309+
*
83118310
* @param token - Login token previously received from homeserver
8312-
* @returns Promise which resolves to a LoginResponse object
8313-
* @returns Rejects: with an error response.
83148311
*/
83158312
public loginWithToken(token: string): Promise<LoginResponse> {
83168313
return this.login("m.login.token", {

0 commit comments

Comments
 (0)