mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-19 09:01:18 +00:00
NORY-46: add basic action to create client
This commit is contained in:
parent
92b92e13b5
commit
7da7a3c8ca
1 changed files with 29 additions and 0 deletions
29
dashboard/src/lib/action/client.ts
Normal file
29
dashboard/src/lib/action/client.ts
Normal 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 });
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue