MCPcopy Create free account
hub / github.com/hashintel/hash / createKratosIdentity

Function createKratosIdentity

apps/hash-api/src/auth/ory-kratos.ts:37–72  ·  view source on GitHub ↗
(
  params: Omit<CreateIdentityBody, "schema_id" | "traits"> & {
    traits: KratosUserIdentityTraits;
    /**
     * If true, all emails in the traits will be marked as verified
     * in the created identity. This is useful in tests to bypass
     * email verification requirements.
     */
    verifyEmails?: boolean;
  },
)

Source from the content-addressed store, hash-verified

35 .map(({ value }) => normalizeEmail(value));
36
37export const createKratosIdentity = async (
38 params: Omit<CreateIdentityBody, "schema_id" | "traits"> & {
39 traits: KratosUserIdentityTraits;
40 /**
41 * If true, all emails in the traits will be marked as verified
42 * in the created identity. This is useful in tests to bypass
43 * email verification requirements.
44 */
45 verifyEmails?: boolean;
46 },
47): Promise<KratosUserIdentity> => {
48 const { verifyEmails, ...rest } = params;
49
50 const createIdentityBody: CreateIdentityBody = {
51 schema_id: "default",
52 ...rest,
53 };
54
55 if (verifyEmails) {
56 createIdentityBody.verifiable_addresses = params.traits.emails.map(
57 (email) => ({
58 value: email,
59 verified: true,
60 verified_at: new Date().toISOString(),
61 via: "email" as const,
62 status: "completed",
63 }),
64 );
65 }
66
67 const { data: kratosUserIdentity } = await kratosIdentityApi.createIdentity({
68 createIdentityBody,
69 });
70
71 return kratosUserIdentity;
72};
73
74export const deleteKratosIdentity = async (params: {
75 kratosIdentityId: string;

Callers 5

setup-admin.tsFile · 0.90
ensureUsersAreSeededFunction · 0.90
createTestUserFunction · 0.90
user.test.tsFile · 0.90

Calls 1

mapMethod · 0.45

Tested by

no test coverage detected