Skip to content

Commit

Permalink
Fixed TOTP MFA types
Browse files Browse the repository at this point in the history
  • Loading branch information
hopleus committed Jan 10, 2025
1 parent 180865b commit 567f8b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/stack-shared/src/interface/clientInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ export class StackClientInterface {
email: string,
password: string,
session: InternalSession
): Promise<Result<{ accessToken: string, refreshToken: string }, KnownErrors["EmailPasswordMismatch"]>> {
): Promise<Result<{ accessToken: string, refreshToken: string }, KnownErrors["EmailPasswordMismatch"] | KnownErrors["MultiFactorAuthenticationRequired"]>> {
const res = await this.sendClientRequestAndCatchKnownError(
"/auth/password/sign-in",
{
Expand All @@ -777,7 +777,7 @@ export class StackClientInterface {
}),
},
session,
[KnownErrors.EmailPasswordMismatch]
[KnownErrors.EmailPasswordMismatch, KnownErrors.MultiFactorAuthenticationRequired]
);

if (res.status === "error") {
Expand Down
4 changes: 3 additions & 1 deletion packages/stack/src/components/credential-sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useTranslation } from "../lib/translations";
import { FormWarningText } from "./elements/form-warning";
import { KnownErrors } from "@stackframe/stack-shared";
import { throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import {Json} from "@stackframe/stack-shared/dist/utils/json";

function OTP(props: {
onBack: () => void,
Expand Down Expand Up @@ -112,7 +113,8 @@ export function CredentialSignIn() {
}
} catch (e) {
if (e instanceof KnownErrors.MultiFactorAuthenticationRequired) {
setNonce(e.details?.attempt_code ?? throwErr("attempt code missing"));
const details: { attempt_code: string } | undefined = e.details as any;
setNonce(details?.attempt_code ?? throwErr("attempt code missing"));
} else {
throw e;
}
Expand Down
8 changes: 2 additions & 6 deletions packages/stack/src/lib/stack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
email: string,
password: string,
noRedirect?: boolean,
}): Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"] | KnownErrors["MultiFactorAuthenticationRequired"] | KnownErrors["InvalidTotpCode"]>> {
}): Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"] | KnownErrors["MultiFactorAuthenticationRequired"]>> {
this._ensurePersistentTokenStore();

const session = await this._getSession();
Expand All @@ -1362,10 +1362,6 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
try {
result = await this._interface.signInWithCredential(options.email, options.password, session);
} catch (e) {
if (e instanceof KnownErrors.InvalidTotpCode) {
return Result.error(e);
}

throw e;
}

Expand Down Expand Up @@ -3337,7 +3333,7 @@ export type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId ex
readonly urls: Readonly<HandlerUrls>,

signInWithOAuth(provider: string): Promise<void>,
signInWithCredential(options: { email: string, password: string, noRedirect?: boolean }): Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"] | KnownErrors["InvalidTotpCode"]>>,
signInWithCredential(options: { email: string, password: string, noRedirect?: boolean }): Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"] | KnownErrors["MultiFactorAuthenticationRequired"]>>,
signUpWithCredential(options: { email: string, password: string, noRedirect?: boolean }): Promise<Result<undefined, KnownErrors["UserEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"]>>,
signInWithPasskey(): Promise<Result<undefined, KnownErrors["PasskeyAuthenticationFailed"]| KnownErrors["InvalidTotpCode"] | KnownErrors["PasskeyWebAuthnError"]>>,
callOAuthCallback(): Promise<boolean>,
Expand Down

0 comments on commit 567f8b2

Please sign in to comment.