1
0
Fork 0
mirror of https://codeberg.org/MarkusThielker/next-ory.git synced 2025-07-01 20:49:18 +00:00

NORY-14: refactor Kratos and Hydra APIs (authentication)

This commit is contained in:
Markus Thielker 2024-12-01 15:39:34 +01:00
parent 215d47e888
commit 9ee7da3a6c
No known key found for this signature in database
12 changed files with 51 additions and 27 deletions

View file

@ -3,7 +3,7 @@
import { AxiosError } from 'axios';
import React, { DependencyList, useEffect, useState } from 'react';
import { kratos } from './sdk/kratos';
import { kratos } from './sdk/client';
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
export const HandleError = (

View file

@ -1,3 +1,3 @@
export * from './hooks';
export * from './ui';
export * from './sdk/kratos';
export * from './sdk/client';

View file

@ -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,
},
}),
));
}

View file

@ -0,0 +1,39 @@
'use server';
import { Configuration, FrontendApi, 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;
}
// ####################################################################################
// 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;
}