Skip to content

Commit

Permalink
Add new field to LoginSuccess to show add current device screen (#2759)
Browse files Browse the repository at this point in the history
* Add new field to LoginSuccess to show add current device screen

* Add field to current tests
  • Loading branch information
lmuntaner authored Dec 20, 2024
1 parent 2fe1683 commit edb52b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/frontend/src/components/authenticateBox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const authenticateBox = async ({
connection: AuthenticatedConnection;
newAnchor: boolean;
authnMethod: "pin" | "passkey" | "recovery";
showAddCurrentDevice: boolean;
}> => {
const promptAuth = async (autoSelectIdentity?: bigint) =>
authenticateBoxFlow<PinIdentityMaterial>({
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/src/utils/iiConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe("Connection.login", () => {
expect(loginResult.kind).toBe("loginSuccess");
if (loginResult.kind === "loginSuccess") {
expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection);
expect(loginResult.showAddCurrentDevice).toBe(false);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith(
[convertToCredentialData(mockDevice)],
Expand Down Expand Up @@ -208,6 +209,7 @@ describe("Connection.login", () => {

expect(secondLoginResult.kind).toBe("loginSuccess");
if (secondLoginResult.kind === "loginSuccess") {
expect(secondLoginResult.showAddCurrentDevice).toBe(true);
expect(secondLoginResult.connection).toBeInstanceOf(
AuthenticatedConnection
);
Expand Down Expand Up @@ -258,6 +260,7 @@ describe("Connection.login", () => {

expect(secondLoginResult.kind).toBe("loginSuccess");
if (secondLoginResult.kind === "loginSuccess") {
expect(secondLoginResult.showAddCurrentDevice).toBe(false);
expect(secondLoginResult.connection).toBeInstanceOf(
AuthenticatedConnection
);
Expand Down Expand Up @@ -291,6 +294,7 @@ describe("Connection.login", () => {

expect(loginResult.kind).toBe("loginSuccess");
if (loginResult.kind === "loginSuccess") {
expect(loginResult.showAddCurrentDevice).toBe(false);
expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith(
Expand Down Expand Up @@ -318,6 +322,7 @@ describe("Connection.login", () => {

expect(loginResult.kind).toBe("loginSuccess");
if (loginResult.kind === "loginSuccess") {
expect(loginResult.showAddCurrentDevice).toBe(false);
expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith(
Expand Down Expand Up @@ -358,6 +363,7 @@ describe("Connection.login", () => {

expect(secondLoginResult.kind).toBe("loginSuccess");
if (secondLoginResult.kind === "loginSuccess") {
expect(secondLoginResult.showAddCurrentDevice).toBe(false);
expect(secondLoginResult.connection).toBeInstanceOf(
AuthenticatedConnection
);
Expand Down Expand Up @@ -391,6 +397,7 @@ describe("Connection.login", () => {

expect(loginResult.kind).toBe("loginSuccess");
if (loginResult.kind === "loginSuccess") {
expect(loginResult.showAddCurrentDevice).toBe(false);
expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith(
Expand Down Expand Up @@ -419,6 +426,7 @@ describe("Connection.login", () => {
expect(loginResult.kind).toBe("loginSuccess");
if (loginResult.kind === "loginSuccess") {
expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection);
expect(loginResult.showAddCurrentDevice).toBe(false);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith(
[convertToCredentialData(mockDevice)],
Expand Down Expand Up @@ -461,6 +469,7 @@ describe("Connection.login", () => {
expect(secondLoginResult.connection).toBeInstanceOf(
AuthenticatedConnection
);
expect(secondLoginResult.showAddCurrentDevice).toBe(false);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(2);
expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenNthCalledWith(
2,
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/utils/iiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type LoginSuccess = {
kind: "loginSuccess";
connection: AuthenticatedConnection;
userNumber: bigint;
showAddCurrentDevice: boolean;
};

export type RegFlowNextStep =
Expand Down Expand Up @@ -323,6 +324,7 @@ export class Connection {
actor
),
userNumber,
showAddCurrentDevice: false,
};
}

Expand Down Expand Up @@ -460,6 +462,7 @@ export class Connection {
kind: "loginSuccess",
userNumber,
connection,
showAddCurrentDevice: cancelledRpIds.size > 0,
};
};
fromIdentity = async (
Expand All @@ -480,6 +483,7 @@ export class Connection {
kind: "loginSuccess",
userNumber,
connection,
showAddCurrentDevice: false,
};
};

Expand Down Expand Up @@ -520,6 +524,7 @@ export class Connection {
userNumber,
actor
),
showAddCurrentDevice: false,
};
};

Expand Down
4 changes: 4 additions & 0 deletions src/showcase/src/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const registerFlowOpts: RegisterFlowOpts = {
kind: "loginSuccess",
userNumber: BigInt(12356),
connection: mockConnection,
showAddCurrentDevice: false,
};
},
registrationAllowed: true,
Expand Down Expand Up @@ -122,6 +123,7 @@ export const iiFlows: Record<string, () => void> = {
kind: "loginSuccess",
userNumber: BigInt(1234),
connection: mockConnection,
showAddCurrentDevice: false,
});
},
allowPinLogin: true,
Expand All @@ -138,6 +140,7 @@ export const iiFlows: Record<string, () => void> = {
kind: "loginSuccess",
userNumber: BigInt(1234),
connection: mockConnection,
showAddCurrentDevice: false,
});
},
recover: () => {
Expand All @@ -146,6 +149,7 @@ export const iiFlows: Record<string, () => void> = {
kind: "loginSuccess",
userNumber: BigInt(1234),
connection: mockConnection,
showAddCurrentDevice: false,
});
},
retrievePinIdentityMaterial: ({ userNumber }) => {
Expand Down

0 comments on commit edb52b8

Please sign in to comment.