(
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;
},
)
| 35 | .map(({ value }) => normalizeEmail(value)); |
| 36 | |
| 37 | export 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 | |
| 74 | export const deleteKratosIdentity = async (params: { |
| 75 | kratosIdentityId: string; |
no test coverage detected