diff --git a/apps/portal/src/server/router/offers/offers-profile-router.ts b/apps/portal/src/server/router/offers/offers-profile-router.ts index c29dfde5..9cac7feb 100644 --- a/apps/portal/src/server/router/offers/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers/offers-profile-router.ts @@ -10,7 +10,7 @@ import { } from '~/mappers/offers-mappers'; import { baseCurrencyString } from '~/utils/offers/currency'; import { convert } from '~/utils/offers/currency/currencyExchange'; -import generateRandomName from '~/utils/offers/randomNameGenerator'; +import { generateRandomName, generateRandomStringForToken } from '~/utils/offers/randomGenerator'; import { createValidationRegex } from '~/utils/offers/zodRegex'; import { createRouter } from '../context'; @@ -264,7 +264,7 @@ export const offersProfileRouter = createRouter() // TODO: add more const token = crypto .createHash('sha256') - .update(Date.now().toString()) + .update(Date.now().toString() + generateRandomStringForToken()) .digest('hex'); // Generate random name until unique diff --git a/apps/portal/src/utils/offers/randomNameGenerator.ts b/apps/portal/src/utils/offers/randomGenerator.ts similarity index 62% rename from apps/portal/src/utils/offers/randomNameGenerator.ts rename to apps/portal/src/utils/offers/randomGenerator.ts index ff02e503..c0a05ac9 100644 --- a/apps/portal/src/utils/offers/randomNameGenerator.ts +++ b/apps/portal/src/utils/offers/randomGenerator.ts @@ -1,4 +1,5 @@ -import type { Config } from 'unique-names-generator'; +import type { Config} from 'unique-names-generator'; +import { countries, names } from 'unique-names-generator'; import { adjectives, animals,colors, uniqueNamesGenerator } from 'unique-names-generator'; import { PrismaClient } from '@prisma/client'; @@ -10,8 +11,7 @@ const customConfig: Config = { separator: '-', }; - -export default async function generateRandomName(): Promise { +export async function generateRandomName(): Promise { let uniqueName: string = uniqueNamesGenerator(customConfig); let sameNameProfiles = await prisma.offersProfile.findMany({ @@ -30,4 +30,15 @@ export default async function generateRandomName(): Promise { } return uniqueName +} + +const tokenConfig: Config = { + dictionaries: [adjectives, colors, animals, countries, names] + .sort((_a, _b) => 0.5 - Math.random()), + length: 5, + separator: '-', +}; + +export function generateRandomStringForToken(): string { + return uniqueNamesGenerator(tokenConfig) } \ No newline at end of file