mirror of
https://github.com/logto-io/logto.git
synced 2025-04-07 23:01:25 -05:00
refactor: replace parse()
with native Date
This commit is contained in:
parent
ca126026e9
commit
931750f468
5 changed files with 9 additions and 9 deletions
|
@ -37,7 +37,7 @@ const now = Date.now();
|
|||
jest.mock(
|
||||
'date-fns',
|
||||
jest.fn(() => ({
|
||||
add: jest.fn((_: Date, { seconds }: { seconds: number }) => new Date(now + seconds * 1000)),
|
||||
addSeconds: jest.fn((_: Date, seconds: number) => new Date(now + seconds * 1000)),
|
||||
}))
|
||||
);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { CreateApplication, OidcClientMetadata } from '@logto/schemas';
|
||||
import { ApplicationType } from '@logto/schemas';
|
||||
import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas/lib/seeds';
|
||||
import { add } from 'date-fns';
|
||||
import { addSeconds } from 'date-fns';
|
||||
import type { AdapterFactory, AllClientMetadata } from 'oidc-provider';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
|
||||
|
@ -99,7 +99,7 @@ export default function postgresAdapter(modelName: string): ReturnType<AdapterFa
|
|||
modelName,
|
||||
id,
|
||||
payload,
|
||||
expiresAt: add(Date.now(), { seconds: expiresIn }).valueOf(),
|
||||
expiresAt: addSeconds(Date.now(), expiresIn).valueOf(),
|
||||
}),
|
||||
find: async (id) => findPayloadById(modelName, id),
|
||||
findByUserCode: async (userCode) => findPayloadByPayloadField(modelName, 'userCode', userCode),
|
||||
|
|
|
@ -7,7 +7,7 @@ import { OidcModelInstances } from '@logto/schemas';
|
|||
import { convertToIdentifiers, convertToTimestamp } from '@logto/shared';
|
||||
import type { Nullable } from '@silverhand/essentials';
|
||||
import { conditional } from '@silverhand/essentials';
|
||||
import { add, isBefore } from 'date-fns';
|
||||
import { addSeconds, isBefore } from 'date-fns';
|
||||
import type { ValueExpression } from 'slonik';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
|
@ -30,7 +30,7 @@ const isConsumed = (modelName: string, consumedAt: Nullable<number>): boolean =>
|
|||
return Boolean(consumedAt);
|
||||
}
|
||||
|
||||
return isBefore(add(consumedAt, { seconds: refreshTokenReuseInterval }), Date.now());
|
||||
return isBefore(addSeconds(consumedAt, refreshTokenReuseInterval), Date.now());
|
||||
};
|
||||
|
||||
const withConsumed = <T>(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { dateRegex } from '@logto/core-kit';
|
||||
import { endOfDay, format, parse, startOfDay, subDays } from 'date-fns';
|
||||
import { endOfDay, format, subDays } from 'date-fns';
|
||||
import { object, string } from 'zod';
|
||||
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
|
@ -74,7 +74,7 @@ export default function dashboardRoutes<T extends AuthedRouter>(router: T) {
|
|||
query: { date },
|
||||
} = ctx.guard;
|
||||
|
||||
const targetDay = date ? parse(date, 'yyyy-MM-dd', startOfDay(Date.now())) : Date.now(); // Defaults to today
|
||||
const targetDay = date ? new Date(date) : new Date(); // Defaults to today
|
||||
const [
|
||||
// DAU: Daily Active User
|
||||
last30DauCounts,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { LogType, PasscodeType } from '@logto/schemas';
|
||||
import { logTypeGuard } from '@logto/schemas';
|
||||
import type { Truthy } from '@silverhand/essentials';
|
||||
import { addSeconds, isAfter, isValid, parseISO } from 'date-fns';
|
||||
import { addSeconds, isAfter, isValid } from 'date-fns';
|
||||
import type { Context } from 'koa';
|
||||
import type { Provider } from 'oidc-provider';
|
||||
import type { ZodType } from 'zod';
|
||||
|
@ -60,7 +60,7 @@ export const getVerificationStorageFromInteraction = async <T = VerificationStor
|
|||
};
|
||||
|
||||
export const checkValidateExpiration = (expiresAt: string) => {
|
||||
const parsed = parseISO(expiresAt);
|
||||
const parsed = new Date(expiresAt);
|
||||
assertThat(
|
||||
isValid(parsed) && isAfter(parsed, Date.now()),
|
||||
new RequestError({ code: 'session.verification_expired', status: 401 })
|
||||
|
|
Loading…
Add table
Reference in a new issue