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

NORY-46: add basic action to create client

This commit is contained in:
Markus Thielker 2025-01-26 20:33:21 +01:00
parent 92b92e13b5
commit 7da7a3c8ca

View file

@ -0,0 +1,29 @@
'use server';
import { clientFormSchema } from '@/lib/forms/client-form';
import { z } from 'zod';
import { getFrontendApi, getOAuth2Api } from '@/ory/sdk/server';
import { cookies } from 'next/headers';
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';
}
console.log(session.identity?.traits.email, 'posted form', formData);
const oauthApi = await getOAuth2Api();
return await oauthApi.createOAuth2Client({ oAuth2Client: formData });
}