diff --git a/web-portal/backend/src/apps/apps.service.ts b/web-portal/backend/src/apps/apps.service.ts index e17a2ab..34a0361 100644 --- a/web-portal/backend/src/apps/apps.service.ts +++ b/web-portal/backend/src/apps/apps.service.ts @@ -4,8 +4,7 @@ import { AppRule, PrismaClient, Tenant, RuleType } from '@/.generated/client'; import { UserService } from '../user/user.service'; import { createHash, randomBytes } from 'crypto'; import { Request } from 'express'; -import { nanoid } from 'nanoid'; -import { NANO_ID_LENGTH } from '../utils/const'; +import { nanoid } from '@/src/utils/const'; @Injectable() export class AppsService { @@ -85,7 +84,7 @@ export class AppsService { if (!tenants) return; const newApp = await this.prisma.client.app.create({ data: { - id: nanoid(NANO_ID_LENGTH), + id: nanoid(), tenantId: tenants[0].id, name, description, diff --git a/web-portal/backend/src/tenant/tenant.service.ts b/web-portal/backend/src/tenant/tenant.service.ts index f8e4c21..8c9269e 100644 --- a/web-portal/backend/src/tenant/tenant.service.ts +++ b/web-portal/backend/src/tenant/tenant.service.ts @@ -2,8 +2,7 @@ import { Injectable, Inject, HttpException, HttpStatus } from '@nestjs/common'; import { CustomPrismaService } from 'nestjs-prisma'; import { PrismaClient } from '@/.generated/client'; import { createHash, randomBytes } from 'crypto'; -import { nanoid } from 'nanoid' -import { NANO_ID_LENGTH } from '../utils/const'; +import { nanoid } from '@/src/utils/const'; @Injectable() export class TenantService { @@ -28,7 +27,7 @@ export class TenantService { const tenant = await this.prisma.client.tenant.create({ data: { - id: nanoid(NANO_ID_LENGTH), + id: nanoid(), enterpriseId: enterprise.id, secretKey: hashedKey, }, diff --git a/web-portal/backend/src/user/user.service.ts b/web-portal/backend/src/user/user.service.ts index 7cb60f9..d01eafc 100644 --- a/web-portal/backend/src/user/user.service.ts +++ b/web-portal/backend/src/user/user.service.ts @@ -6,8 +6,7 @@ import { TenantService } from '../tenant/tenant.service'; import { unsealData } from 'iron-session'; import { Request } from 'express'; import { ISession, SESSION_OPTIONS } from '../siwe/siwe.service'; -import { nanoid } from 'nanoid'; -import { NANO_ID_LENGTH } from '../utils/const'; +import { nanoid } from '@/src/utils/const'; @Injectable() export class UserService { @@ -66,7 +65,7 @@ export class UserService { } const newUser = await this.prisma.client.user.create({ data: { - id: nanoid(NANO_ID_LENGTH), + id: nanoid(), ethAddress: createHash('sha256').update(ethAddress).digest('hex'), orgs: { create: { diff --git a/web-portal/backend/src/utils/const.ts b/web-portal/backend/src/utils/const.ts index 7525bae..a4322dc 100644 --- a/web-portal/backend/src/utils/const.ts +++ b/web-portal/backend/src/utils/const.ts @@ -1,2 +1,5 @@ +import { customAlphabet } from "nanoid"; export const NANO_ID_LENGTH = 10; // https://zelark.github.io/nano-id-cc/ export const PORTR_ADDRESS = '0x54d5f8a0e0f06991e63e46420bcee1af7d9fe944'; +export const NANO_ID_ALPHABETS = '123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz'; +export const nanoid = () => customAlphabet(NANO_ID_ALPHABETS, NANO_ID_LENGTH);