Skip to content

Commit

Permalink
nano id update
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo committed May 23, 2024
1 parent 9980969 commit 3ae0eba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
5 changes: 2 additions & 3 deletions web-portal/backend/src/apps/apps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions web-portal/backend/src/tenant/tenant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
Expand Down
5 changes: 2 additions & 3 deletions web-portal/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 3 additions & 0 deletions web-portal/backend/src/utils/const.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 3ae0eba

Please sign in to comment.