Skip to content

Commit

Permalink
refactor(core): rebase the core interaction apis change
Browse files Browse the repository at this point in the history
rebase the core interaction apis change
  • Loading branch information
simeng-li committed Jun 26, 2024
1 parent 79dfd1d commit 64ca1fb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function verificationCodeRoutes<T extends WithLogContext>(
await ctx.interactionSession.save();

ctx.body = {
verificationId,
verificationId: codeVerificationRecord.id,
};

return next();
Expand Down
36 changes: 35 additions & 1 deletion packages/integration-tests/src/helpers/experience/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
* @fileoverview This file contains the successful interaction flow helper functions that use the experience APIs.
*/

import { InteractionEvent, type InteractionIdentifier } from '@logto/schemas';
import {
InteractionEvent,
type InteractionIdentifier,
type VerificationCodeIdentifier,
} from '@logto/schemas';

import { identifyUser } from '#src/api/experience-api/index.js';
import { createPasswordVerification } from '#src/api/experience-api/password-verification.js';

import { initClient, logoutClient, processSession } from '../client.js';

import {
successfullySendVerificationCode,
successfullyVerifyVerificationCode,
} from './verification-code.js';

export const signInWithPassword = async ({
identifier,
password,
Expand All @@ -33,3 +42,28 @@ export const signInWithPassword = async ({
await processSession(client, redirectTo);
await logoutClient(client);
};

export const signInWithVerificationCode = async (identifier: VerificationCodeIdentifier) => {
const client = await initClient();

const { verificationId, code } = await successfullySendVerificationCode(client, {
identifier,
interactionEvent: InteractionEvent.SignIn,
});

const verifiedVerificationId = await successfullyVerifyVerificationCode(client, {
identifier,
verificationId,
code,
});

await client.successSend(identifyUser, {
interactionEvent: InteractionEvent.SignIn,
verificationId: verifiedVerificationId,
});

const { redirectTo } = await client.submitInteraction('v2');

await processSession(client, redirectTo);
await logoutClient(client);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { deleteUser } from '#src/api/admin-user.js';
import { signInWithVerificationCode } from '#src/helpers/experience/index.js';
import { enableAllVerificationCodeSignInMethods } from '#src/helpers/sign-in-experience.js';
import { generateNewUser } from '#src/helpers/user.js';
import { devFeatureTest } from '#src/utils.js';

const verificationIdentifierType: readonly ['email', 'phone'] = Object.freeze(['email', 'phone']);

const identifiersTypeToUserProfile = Object.freeze({
email: 'primaryEmail',
phone: 'primaryPhone',
});

devFeatureTest.describe('Sign-in with verification code happy path', () => {
beforeAll(async () => {
await enableAllVerificationCodeSignInMethods();
});

it.each(verificationIdentifierType)(
'Should sign-in with verification code using %p',
async (identifier) => {
const { userProfile, user } = await generateNewUser({
[identifiersTypeToUserProfile[identifier]]: true,
password: true,
});

await signInWithVerificationCode({
type: identifier,
value: userProfile[identifiersTypeToUserProfile[identifier]]!,
});

await deleteUser(user.id);
}
);
});

0 comments on commit 64ca1fb

Please sign in to comment.