mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
Merge pull request #2885 from logto-io/gao-log-5125-core-library-factory-logto-config
refactor(core): migrate logto config library to factory mode
This commit is contained in:
commit
76bd2bc7d0
3 changed files with 31 additions and 24 deletions
|
@ -5,7 +5,7 @@ import type { PostgreSql } from '@withtyped/postgres';
|
|||
import type { QueryClient } from '@withtyped/server';
|
||||
import type { DatabasePool } from 'slonik';
|
||||
|
||||
import { getOidcConfigs } from '#src/libraries/logto-config.js';
|
||||
import { createLogtoConfigLibrary } from '#src/libraries/logto-config.js';
|
||||
import { appendPath } from '#src/utils/url.js';
|
||||
|
||||
import { checkAlterationState } from './check-alteration-state.js';
|
||||
|
@ -108,7 +108,8 @@ class EnvSet {
|
|||
this.#pool = pool;
|
||||
this.#queryClient = createQueryClient(this.databaseUrl, this.isTest);
|
||||
|
||||
const [, oidcConfigs] = await Promise.all([checkAlterationState(pool), getOidcConfigs(pool)]);
|
||||
const { getOidcConfigs } = createLogtoConfigLibrary(pool);
|
||||
const [, oidcConfigs] = await Promise.all([checkAlterationState(pool), getOidcConfigs()]);
|
||||
this.#oidc = await loadOidcValues(
|
||||
appendPath(this.values.endpoint, '/oidc').toString(),
|
||||
oidcConfigs
|
||||
|
|
|
@ -15,8 +15,10 @@ const { privateKey } = generateKeyPairSync('rsa', {
|
|||
},
|
||||
});
|
||||
|
||||
export const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => ({
|
||||
const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => ({
|
||||
[LogtoOidcConfigKey.PrivateKeys]: [privateKey],
|
||||
[LogtoOidcConfigKey.CookieKeys]: ['LOGTOSEKRIT1'],
|
||||
[LogtoOidcConfigKey.RefreshTokenReuseInterval]: 3,
|
||||
});
|
||||
|
||||
export const createLogtoConfigLibrary = () => ({ getOidcConfigs });
|
||||
|
|
|
@ -5,7 +5,8 @@ import chalk from 'chalk';
|
|||
import type { CommonQueryMethods } from 'slonik';
|
||||
import { z, ZodError } from 'zod';
|
||||
|
||||
export const getOidcConfigs = async (pool: CommonQueryMethods): Promise<LogtoOidcConfigType> => {
|
||||
export const createLogtoConfigLibrary = (pool: CommonQueryMethods) => {
|
||||
const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => {
|
||||
try {
|
||||
const { rows } = await getRowsByKeys(pool, Object.values(LogtoOidcConfigKey));
|
||||
|
||||
|
@ -31,4 +32,7 @@ export const getOidcConfigs = async (pool: CommonQueryMethods): Promise<LogtoOid
|
|||
);
|
||||
throw new Error('Failed to get configs');
|
||||
}
|
||||
};
|
||||
|
||||
return { getOidcConfigs };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue