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

Improve types around login, registration, UIA and identity servers #3537

Merged
merged 14 commits into from
Jul 4, 2023
5 changes: 3 additions & 2 deletions src/@types/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ type PhoneLoginIdentifier = {
type SpecUserIdentifier = UserLoginIdentifier | ThirdPartyLoginIdentifier | PhoneLoginIdentifier;

/**
* User Identifiers usable for login & user-interactive authentication
* Extensibly allows more than Matrix specified identifiers
* User Identifiers usable for login & user-interactive authentication.
*
* Extensibly allows more than Matrix specified identifiers.
*/
export type UserIdentifier =
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
| SpecUserIdentifier
Expand Down
8 changes: 6 additions & 2 deletions src/@types/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
import { AuthDict } from "../interactive-auth";

/**
* The request body of a call to POST https://spec.matrix.org/v1.7/client-server-api/#post_matrixclientv3register
* The request body of a call to `POST /_matrix/client/v3/register`
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
*
* @see https://spec.matrix.org/v1.7/client-server-api/#post_matrixclientv3register
*/
export interface RegisterRequest {
/**
Expand Down Expand Up @@ -68,7 +70,9 @@ export interface RegisterRequest {
}

/**
* The result of a successful call to POST https://spec.matrix.org/v1.7/client-server-api/#post_matrixclientv3register
* The result of a successful call to `POST /_matrix/client/v3/register`
*
* @see https://spec.matrix.org/v1.7/client-server-api/#post_matrixclientv3register
*/
export interface RegisterResponse {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7813,7 +7813,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}

/**
@returns Promise which resolves to a LoginResponse object
* @returns Promise which resolves to a LoginResponse object
* @returns Rejects: with an error response.
*/
public loginWithPassword(user: string, password: string): Promise<LoginResponse> {
Expand Down
13 changes: 2 additions & 11 deletions src/interactive-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ export class InteractiveAuth<T> {
private readonly requestEmailTokenCallback: IOpts<T>["requestEmailToken"];
private readonly supportedStages?: Set<string>;

// The current latest data as part of the interactive auth
// MatrixError can occur if the error from server is not a 401 UIA error
private data: IAuthData | MatrixError;
// The current latest data received from the server during the user interactive auth flow.
private data: IAuthData;
private emailSid?: string;
private requestingEmailToken = false;
private attemptAuthDeferred: IDeferred<T> | null = null;
Expand Down Expand Up @@ -602,14 +601,6 @@ export class InteractiveAuth<T> {
return;
}

if (this.data instanceof MatrixError) {
this.stateUpdatedCallback(nextStage, {
errcode: this.data?.errcode || "",
error: this.data?.data.error || "",
});
return;
}

this.stateUpdatedCallback(nextStage, nextStage === EMAIL_STAGE_TYPE ? { emailSid: this.emailSid } : {});
}

Expand Down
4 changes: 2 additions & 2 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,10 +1376,10 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
const relation = this.getWireContent()?.["m.relates_to"];
if (
this.isState() &&
relation?.rel_type &&
!!relation?.rel_type &&
([RelationType.Replace, RelationType.Thread] as string[]).includes(relation.rel_type)
) {
// State events cannot be m.replace relations
// State events cannot be m.replace or m.thread relations
return false;
}
return !!(relation?.rel_type && relation.event_id && (relType ? relation.rel_type === relType : true));
Expand Down