diff --git a/dashboard/src/middleware.ts b/dashboard/src/middleware.ts index 7bfb759..4ef97c3 100644 --- a/dashboard/src/middleware.ts +++ b/dashboard/src/middleware.ts @@ -1,6 +1,6 @@ import { NextResponse } from 'next/server'; -import { getFrontendApi } from '@/ory/sdk/hydra'; import { cookies } from 'next/headers'; +import { getFrontendApi } from '@/ory/sdk/server'; export async function middleware() { diff --git a/dashboard/src/ory/hooks.tsx b/dashboard/src/ory/hooks.tsx index fa4797f..c5b5d26 100644 --- a/dashboard/src/ory/hooks.tsx +++ b/dashboard/src/ory/hooks.tsx @@ -3,7 +3,7 @@ import { AxiosError } from 'axios'; import { DependencyList, useEffect, useState } from 'react'; -import { kratos } from './sdk/kratos'; +import { kratos } from './sdk/client'; // Returns a function which will log the user out export function LogoutLink(deps?: DependencyList) { diff --git a/dashboard/src/ory/index.ts b/dashboard/src/ory/index.ts index c6f14a3..3676992 100644 --- a/dashboard/src/ory/index.ts +++ b/dashboard/src/ory/index.ts @@ -1,2 +1,2 @@ export * from './hooks'; -export * from './sdk/kratos'; +export * from './sdk/client'; diff --git a/dashboard/src/ory/sdk/kratos/index.ts b/dashboard/src/ory/sdk/client/index.ts similarity index 100% rename from dashboard/src/ory/sdk/kratos/index.ts rename to dashboard/src/ory/sdk/client/index.ts diff --git a/dashboard/src/ory/sdk/hydra/index.ts b/dashboard/src/ory/sdk/hydra/index.ts deleted file mode 100644 index 335cd85..0000000 --- a/dashboard/src/ory/sdk/hydra/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -'use server'; - -import { Configuration, OAuth2Api } from '@ory/client'; - -// implemented as a function because of 'use server' -export default async function getHydra() { - return new OAuth2Api(new Configuration( - new Configuration({ - basePath: process.env.ORY_HYDRA_ADMIN_URL, - baseOptions: { - withCredentials: true, - }, - }), - )); -} \ No newline at end of file diff --git a/dashboard/src/ory/sdk/server/index.ts b/dashboard/src/ory/sdk/server/index.ts new file mode 100644 index 0000000..fb2a176 --- /dev/null +++ b/dashboard/src/ory/sdk/server/index.ts @@ -0,0 +1,94 @@ +'use server'; + +import { Configuration, FrontendApi, IdentityApi, MetadataApi, OAuth2Api } from '@ory/client'; + + +// #################################################################################### +// OAuth2 API +// #################################################################################### + +const oAuth2Api = new OAuth2Api(new Configuration( + { + basePath: process.env.ORY_HYDRA_ADMIN_URL, + baseOptions: { + withCredentials: true, + }, + }, +)); + +export async function getOAuth2Api() { + return oAuth2Api; +} + + +// #################################################################################### +// Hydra Metadata API +// #################################################################################### + +const hydraMetadataApi = new MetadataApi(new Configuration( + { + basePath: process.env.ORY_HYDRA_ADMIN_URL, + baseOptions: { + withCredentials: true, + }, + }, +)); + +export async function getHydraMetadataApi() { + return hydraMetadataApi; +} + + +// #################################################################################### +// Frontend API +// #################################################################################### + +const frontendApi = new FrontendApi( + new Configuration({ + basePath: process.env.NEXT_PUBLIC_ORY_KRATOS_URL, + baseOptions: { + withCredentials: true, + }, + }), +); + +export async function getFrontendApi() { + return frontendApi; +} + + +// #################################################################################### +// Identity API +// #################################################################################### + +const identityApi = new IdentityApi(new Configuration( + { + basePath: process.env.ORY_KRATOS_ADMIN_URL, + baseOptions: { + withCredentials: true, + }, + }, +)); + +export async function getIdentityApi() { + return identityApi; +} + + +// #################################################################################### +// Kratos Metadata API +// #################################################################################### + +const kratosMetadataApi = new MetadataApi( + new Configuration( + { + basePath: process.env.ORY_KRATOS_ADMIN_URL, + baseOptions: { + withCredentials: true, + }, + }, + )); + +export async function getKratosMetadataApi() { + return kratosMetadataApi; +}