Skip to content

Commit

Permalink
fix(models): Update ResponseLogin.from_quark()
Browse files Browse the repository at this point in the history
  • Loading branch information
V3L0C1T13S committed Dec 4, 2023
1 parent 49f7421 commit 1ddf224
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/common/models/models/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ import {
SessionInfo,
} from "revolt-api";
import { decodeTime } from "ulid";
import { toSnowflake } from "@reflectcord/common/models";
import { systemUserID } from "@reflectcord/common/rvapi";
import { QuarkConversion } from "../../QuarkConversion";
import { LoginSchema, MFALoginSchema, UserSession } from "../../../sparkle";
import { toCompatibleISO } from "../../../utils/date";

export type APILoginResponse = {
export type APIMFALoginResponse = {
user_id: string,
ticket: string | undefined, // MFA ticket
sms: boolean | undefined,
mfa: boolean | undefined,
backup: boolean,
totp: boolean,
webauthn: null, // FIXME: what type is this?
}

export type APISuccessfulLoginResponse = {
token: string | null,
settings: any,
ticket?: string | undefined, // MFA ticket
sms?: boolean | undefined,
mfa?: boolean | undefined,
user_settings: any,
}

export type APILoginResponse = APISuccessfulLoginResponse | APIMFALoginResponse;

export const ResponseLogin: QuarkConversion<RevoltLoginResponse, APILoginResponse> = {
async to_quark(login) {
const { token } = login;

// TODO: mfa
return {
token: token ?? "",
token: "token" in login ? login.token ?? "" : "",
result: "Success",
user_id: "", // FIXME,
name: "",
Expand All @@ -34,24 +45,28 @@ export const ResponseLogin: QuarkConversion<RevoltLoginResponse, APILoginRespons

if (isMFA) {
return {
token: null,
settings: undefined,
user_id: await toSnowflake(systemUserID),
ticket: login.ticket,
sms: false,
mfa: true,
backup: login.allowed_methods.includes("Recovery"),
totp: login.allowed_methods.includes("Totp"),
webauthn: null,
};
}

if (login.result !== "Success") {
return {
token: null,
settings: undefined,
user_settings: undefined,
};
}

return {
token: login.token,
settings: undefined,
user_settings: {},
};
},
};
Expand Down

0 comments on commit 1ddf224

Please sign in to comment.