From 45117e72129c9e55f813688baa32c6c9fe223d79 Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Wed, 1 Jan 2025 23:11:20 +0100 Subject: [PATCH] NORY-47: refactor identity actions --- dashboard/src/app/(inside)/user/action.ts | 40 +++++++++++++++---- .../src/app/(inside)/user/data-table.tsx | 8 ++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/dashboard/src/app/(inside)/user/action.ts b/dashboard/src/app/(inside)/user/action.ts index bd2ffbd..edf15dc 100644 --- a/dashboard/src/app/(inside)/user/action.ts +++ b/dashboard/src/app/(inside)/user/action.ts @@ -4,10 +4,6 @@ import { getIdentityApi } from '@/ory/sdk/server'; import { revalidatePath } from 'next/cache'; import { UpdateIdentityBody } from '@ory/client/api'; -interface IdentityIdProps { - id: string; -} - interface UpdatedIdentityProps { id: string; body: UpdateIdentityBody; @@ -24,7 +20,7 @@ export async function updateIdentity({ id, body }: UpdatedIdentityProps) { return data; } -export async function deleteIdentitySessions({ id }: IdentityIdProps) { +export async function deleteIdentitySessions(id: string) { const identityApi = await getIdentityApi(); const { data } = await identityApi.deleteIdentitySessions({ id }); @@ -34,7 +30,35 @@ export async function deleteIdentitySessions({ id }: IdentityIdProps) { return data; } -export async function blockIdentity({ id }: IdentityIdProps) { +export async function createRecoveryCode(id: string) { + + const identityApi = await getIdentityApi(); + const { data } = await identityApi.createRecoveryCodeForIdentity({ + createRecoveryCodeForIdentityBody: { + identity_id: id, + }, + }); + + console.log('Created recovery code for user', id, data); + + return data; +} + +export async function createRecoveryLink(id: string) { + + const identityApi = await getIdentityApi(); + const { data } = await identityApi.createRecoveryLinkForIdentity({ + createRecoveryLinkForIdentityBody: { + identity_id: id, + }, + }); + + console.log('Created recovery link for user', id, data); + + return data; +} + +export async function blockIdentity(id: string) { const identityApi = await getIdentityApi(); const { data } = await identityApi.patchIdentity({ @@ -53,7 +77,7 @@ export async function blockIdentity({ id }: IdentityIdProps) { revalidatePath('/user'); } -export async function unblockIdentity({ id }: IdentityIdProps) { +export async function unblockIdentity(id: string) { const identityApi = await getIdentityApi(); const { data } = await identityApi.patchIdentity({ @@ -72,7 +96,7 @@ export async function unblockIdentity({ id }: IdentityIdProps) { revalidatePath('/user'); } -export async function deleteIdentity({ id }: IdentityIdProps) { +export async function deleteIdentity(id: string) { const identityApi = await getIdentityApi(); const { data } = await identityApi.deleteIdentity({ id }); diff --git a/dashboard/src/app/(inside)/user/data-table.tsx b/dashboard/src/app/(inside)/user/data-table.tsx index 39f9ae1..0a478fe 100644 --- a/dashboard/src/app/(inside)/user/data-table.tsx +++ b/dashboard/src/app/(inside)/user/data-table.tsx @@ -259,7 +259,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent - deleteIdentitySessions({ id: currentIdentity.id })}> + deleteIdentitySessions(currentIdentity.id)}> Invalidate sessions @@ -281,7 +281,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent blockIdentity({ id: currentIdentity.id })}> + onClick={() => blockIdentity(currentIdentity.id)}> Block identity @@ -303,7 +303,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent unblockIdentity({ id: currentIdentity.id })}> + onClick={() => unblockIdentity(currentIdentity.id)}> Unblock identity @@ -326,7 +326,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent deleteIdentity({ id: currentIdentity.id })}> + onClick={() => deleteIdentity(currentIdentity.id)}> Delete identity