@@ -8246,27 +8246,33 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
8246
8246
/**
8247
8247
* @returns Promise which resolves to a LoginResponse object
8248
8248
* @returns Rejects: with an error response.
8249
+ *
8250
+ * @deprecated This method has unintuitive behaviour: it updates the `MatrixClient` instance with *some* of the
8251
+ * returned credentials. Instead, call {@link loginRequest} and create a new `MatrixClient` instance using the
8252
+ * results. See https://github.com/matrix-org/matrix-js-sdk/issues/4502.
8249
8253
*/
8250
8254
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
- } ) ;
8255
+ return this . loginRequest ( {
8256
+ ...data ,
8257
+ type : loginType ,
8258
+ } ) . then ( ( response ) => {
8259
+ if ( response . access_token && response . user_id ) {
8260
+ this . http . opts . accessToken = response . access_token ;
8261
+ this . credentials = {
8262
+ userId : response . user_id ,
8263
+ } ;
8264
+ }
8265
+ return response ;
8266
+ } ) ;
8265
8267
}
8266
8268
8267
8269
/**
8268
8270
* @returns Promise which resolves to a LoginResponse object
8269
8271
* @returns Rejects: with an error response.
8272
+ *
8273
+ * @deprecated This method has unintuitive behaviour: it updates the `MatrixClient` instance with *some* of the
8274
+ * returned credentials. Instead, call {@link loginRequest} with `data.type: "m.login.password"`, and create a new
8275
+ * `MatrixClient` instance using the results. See https://github.com/matrix-org/matrix-js-sdk/issues/4502.
8270
8276
*/
8271
8277
public loginWithPassword ( user : string , password : string ) : Promise < LoginResponse > {
8272
8278
return this . login ( "m.login.password" , {
@@ -8311,13 +8317,31 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
8311
8317
* @param token - Login token previously received from homeserver
8312
8318
* @returns Promise which resolves to a LoginResponse object
8313
8319
* @returns Rejects: with an error response.
8320
+ *
8321
+ * @deprecated This method has unintuitive behaviour: it updates the `MatrixClient` instance with *some* of the
8322
+ * returned credentials. Instead, call {@link loginRequest} with `data.type: "m.login.token"`, and create a new
8323
+ * `MatrixClient` instance using the results. See https://github.com/matrix-org/matrix-js-sdk/issues/4502.
8314
8324
*/
8315
8325
public loginWithToken ( token : string ) : Promise < LoginResponse > {
8316
8326
return this . login ( "m.login.token" , {
8317
8327
token : token ,
8318
8328
} ) ;
8319
8329
}
8320
8330
8331
+ /**
8332
+ * Sends a `POST /login` request to the server.
8333
+ *
8334
+ * If successful, this will create a new device and access token for the user.
8335
+ *
8336
+ * @see {@link MatrixClient.loginFlows } which makes a `GET /login` request.
8337
+ * @see https://spec.matrix.org/v1.13/client-server-api/#post_matrixclientv3login
8338
+ *
8339
+ * @param data - Credentials and other details for the login request.
8340
+ */
8341
+ public async loginRequest ( data : LoginRequest ) : Promise < LoginResponse > {
8342
+ return await this . http . authedRequest < LoginResponse > ( Method . Post , "/login" , undefined , data ) ;
8343
+ }
8344
+
8321
8345
/**
8322
8346
* Logs out the current session.
8323
8347
* Obviously, further calls that require authorisation should fail after this
0 commit comments