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

NORY-59: refactor identity queries to use server actions

This commit is contained in:
Markus Thielker 2025-04-06 13:02:56 +02:00
parent 8d10b744e9
commit c2299f0340
3 changed files with 123 additions and 73 deletions

View file

@ -15,6 +15,34 @@ import { eq, ilike, or, sql } from 'drizzle-orm';
import { checkPermission, requireSession } from '@/lib/action/authentication';
import { permission, relation } from '@/lib/permission';
export async function getIdentity(id: string) {
const session = await requireSession();
const allowed = await checkPermission(permission.user.it, relation.access, session.identity!.id);
if (!allowed) {
throw Error('Unauthorised');
}
const identityApi = await getIdentityApi();
const { data } = await identityApi.getIdentity({ id });
console.log('Got identity', data);
return data;
}
export async function getIdentitySchema(id: string) {
const identityApi = await getIdentityApi();
const { data } = await identityApi.getIdentitySchema({ id: id });
console.log('Got identity schema');
return data;
}
interface QueryIdentitiesProps {
page: number,
pageSize: number,
@ -131,6 +159,24 @@ export async function deleteIdentityCredential({ id, type }: DeleteIdentityCrede
return data;
}
export async function listIdentitySessions(id: string) {
const session = await requireSession();
const allowed = await checkPermission(permission.user.session, relation.access, session.identity!.id);
if (!allowed) {
throw Error('Unauthorised');
}
const identityApi = await getIdentityApi();
const { data } = await identityApi.listIdentitySessions({ id });
console.log('Listed identity\'s sessions', data);
revalidatePath('/user');
return data;
}
export async function deleteIdentitySessions(id: string) {
const session = await requireSession();

View file

@ -10,6 +10,7 @@ export const permission = {
link: 'admin.user.link',
session: 'admin.user.session',
state: 'admin.user.state',
trait: 'admin.user.trait',
},
};