1
0
Fork 0
mirror of https://codeberg.org/MarkusThielker/next-ory.git synced 2025-07-04 13:59:17 +00:00

NORY-47: refactor identity actions

This commit is contained in:
Markus Thielker 2025-01-03 22:11:09 +01:00
parent 86784d3b92
commit 95a068645e
No known key found for this signature in database
5 changed files with 4 additions and 4 deletions

View file

@ -0,0 +1,130 @@
'use server';
import { getIdentityApi } from '@/ory/sdk/server';
import { revalidatePath } from 'next/cache';
import { DeleteIdentityCredentialsTypeEnum, UpdateIdentityBody } from '@ory/client';
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,
});
console.log('Updated identity', data);
revalidatePath('/user');
return data;
}
interface DeleteIdentityCredentialProps {
id: string;
type: DeleteIdentityCredentialsTypeEnum;
}
export async function deleteIdentityCredential({ id, type }: DeleteIdentityCredentialProps) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentityCredentials({ id, type });
console.log('Credential removed', data);
revalidatePath('/user');
return data;
}
export async function deleteIdentitySessions(id: string) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentitySessions({ id });
console.log('Deleted identity\'s sessions', data);
revalidatePath('/user');
return data;
}
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({
id,
jsonPatch: [
{
op: 'replace',
path: '/state',
value: 'inactive',
},
],
});
console.log('Blocked identity', data);
revalidatePath('/user');
}
export async function unblockIdentity(id: string) {
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: string) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentity({ id });
console.log('Deleted identity', data);
revalidatePath('/user');
}