next-ory/dashboard/src/app/(inside)/user/action.ts
2024-12-29 00:33:09 +01:00

83 lines
1.9 KiB
TypeScript

'use server';
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;
}
export async function updateIdentity({ id, body }: UpdatedIdentityProps) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.updateIdentity({
id: id,
updateIdentityBody: body,
});
return data;
}
export async function deleteIdentitySessions({ id }: IdentityIdProps) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentitySessions({ id });
console.log('Deleted identity\'s sessions', data);
return data;
}
export async function blockIdentity({ id }: IdentityIdProps) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.patchIdentity({
id,
jsonPatch: [
{
op: 'replace',
path: '/state',
value: 'inactive',
},
],
});
console.log('Blocked identity', data);
revalidatePath('/user');
}
export async function unblockIdentity({ id }: IdentityIdProps) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.patchIdentity({
id,
jsonPatch: [
{
op: 'replace',
path: '/state',
value: 'active',
},
],
});
console.log('Unblocked identity', data);
revalidatePath('/user');
}
export async function deleteIdentity({ id }: IdentityIdProps) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentity({ id });
console.log('Deleted identity', data);
revalidatePath('/user');
}