1
0
Fork 0
mirror of https://codeberg.org/MarkusThielker/next-ory.git synced 2025-04-10 11:58:41 +00:00

NORY-47: refactor identity actions

This commit is contained in:
Markus Thielker 2025-01-01 23:11:20 +01:00
parent 7cef969bb8
commit 45117e7212
No known key found for this signature in database
2 changed files with 36 additions and 12 deletions

View file

@ -4,10 +4,6 @@ import { getIdentityApi } from '@/ory/sdk/server';
import { revalidatePath } from 'next/cache'; import { revalidatePath } from 'next/cache';
import { UpdateIdentityBody } from '@ory/client/api'; import { UpdateIdentityBody } from '@ory/client/api';
interface IdentityIdProps {
id: string;
}
interface UpdatedIdentityProps { interface UpdatedIdentityProps {
id: string; id: string;
body: UpdateIdentityBody; body: UpdateIdentityBody;
@ -24,7 +20,7 @@ export async function updateIdentity({ id, body }: UpdatedIdentityProps) {
return data; return data;
} }
export async function deleteIdentitySessions({ id }: IdentityIdProps) { export async function deleteIdentitySessions(id: string) {
const identityApi = await getIdentityApi(); const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentitySessions({ id }); const { data } = await identityApi.deleteIdentitySessions({ id });
@ -34,7 +30,35 @@ export async function deleteIdentitySessions({ id }: IdentityIdProps) {
return data; 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 identityApi = await getIdentityApi();
const { data } = await identityApi.patchIdentity({ const { data } = await identityApi.patchIdentity({
@ -53,7 +77,7 @@ export async function blockIdentity({ id }: IdentityIdProps) {
revalidatePath('/user'); revalidatePath('/user');
} }
export async function unblockIdentity({ id }: IdentityIdProps) { export async function unblockIdentity(id: string) {
const identityApi = await getIdentityApi(); const identityApi = await getIdentityApi();
const { data } = await identityApi.patchIdentity({ const { data } = await identityApi.patchIdentity({
@ -72,7 +96,7 @@ export async function unblockIdentity({ id }: IdentityIdProps) {
revalidatePath('/user'); revalidatePath('/user');
} }
export async function deleteIdentity({ id }: IdentityIdProps) { export async function deleteIdentity(id: string) {
const identityApi = await getIdentityApi(); const identityApi = await getIdentityApi();
const { data } = await identityApi.deleteIdentity({ id }); const { data } = await identityApi.deleteIdentity({ id });

View file

@ -259,7 +259,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent
</AlertDialogDescription> </AlertDialogDescription>
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogAction onClick={() => deleteIdentitySessions({ id: currentIdentity.id })}> <AlertDialogAction onClick={() => deleteIdentitySessions(currentIdentity.id)}>
Invalidate sessions Invalidate sessions
</AlertDialogAction> </AlertDialogAction>
<AlertDialogCancel> <AlertDialogCancel>
@ -281,7 +281,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogAction <AlertDialogAction
onClick={() => blockIdentity({ id: currentIdentity.id })}> onClick={() => blockIdentity(currentIdentity.id)}>
Block identity Block identity
</AlertDialogAction> </AlertDialogAction>
<AlertDialogCancel> <AlertDialogCancel>
@ -303,7 +303,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogAction <AlertDialogAction
onClick={() => unblockIdentity({ id: currentIdentity.id })}> onClick={() => unblockIdentity(currentIdentity.id)}>
Unblock identity Unblock identity
</AlertDialogAction> </AlertDialogAction>
<AlertDialogCancel> <AlertDialogCancel>
@ -326,7 +326,7 @@ export function IdentityDataTable({ data, pageSize, pageToken, query, fetchIdent
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogAction <AlertDialogAction
onClick={() => deleteIdentity({ id: currentIdentity.id })}> onClick={() => deleteIdentity(currentIdentity.id)}>
Delete identity Delete identity
</AlertDialogAction> </AlertDialogAction>
<AlertDialogCancel> <AlertDialogCancel>