mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-07-04 21:59:18 +00:00
NORY-46: refactor permission checks after rebase
This commit is contained in:
parent
d9a3cde169
commit
222a93886b
3 changed files with 51 additions and 25 deletions
|
@ -2,24 +2,18 @@
|
|||
|
||||
import { clientFormSchema } from '@/lib/forms/client-form';
|
||||
import { z } from 'zod';
|
||||
import { getFrontendApi, getOAuth2Api } from '@/ory/sdk/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getOAuth2Api } from '@/ory/sdk/server';
|
||||
import { checkPermission, requireSession } from '@/lib/action/authentication';
|
||||
import { permission, relation } from '@/lib/permission';
|
||||
|
||||
export async function createClient(
|
||||
formData: z.infer<typeof clientFormSchema>,
|
||||
) {
|
||||
|
||||
const cookie = await cookies();
|
||||
const frontendApi = await getFrontendApi();
|
||||
|
||||
const session = await frontendApi
|
||||
.toSession({ cookie: 'ory_kratos_session=' + cookie.get('ory_kratos_session')?.value })
|
||||
.then((response) => response.data)
|
||||
.catch(() => null);
|
||||
|
||||
if (!session) {
|
||||
console.log('Unauthorised action call');
|
||||
throw 'Unauthorised';
|
||||
const session = await requireSession();
|
||||
const allowed = await checkPermission(permission.client.it, relation.create, session.identity!.id);
|
||||
if (!allowed) {
|
||||
throw Error('Unauthorised');
|
||||
}
|
||||
|
||||
console.log(session.identity?.traits.email, 'posted form', formData);
|
||||
|
|
|
@ -13,6 +13,9 @@ export const permission = {
|
|||
state: 'admin.user.state',
|
||||
trait: 'admin.user.trait',
|
||||
},
|
||||
client: {
|
||||
it: 'admin.client',
|
||||
},
|
||||
};
|
||||
|
||||
export const relation = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue