Replace unsafe id generator with nanoid (#4)

This commit is contained in:
Ivan Alexandrov
2023-12-13 18:28:35 +01:00
committed by GitHub
parent 705eca8c1c
commit c96c4f94b9
4 changed files with 29 additions and 7 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
POSTGRES_PRISMA_URL=postgresql://postgres:1234@localhost
POSTGRES_URL_NON_POOLING=postgresql://postgres:1234@localhost
NEXT_PUBLIC_BASE_URL=http://localhost:3000

29
package-lock.json generated
View File

@@ -23,6 +23,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"lucide-react": "^0.290.0",
"nanoid": "^5.0.4",
"next": "^14.0.4",
"next-plausible": "^3.12.0",
"next-themes": "^0.2.1",
@@ -4173,21 +4174,20 @@
}
},
"node_modules/nanoid": {
"version": "3.3.6",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz",
"integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==",
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.4.tgz",
"integrity": "sha512-vAjmBf13gsmhXSgBrtIclinISzFFy22WwCYoyilZlsrRXNIHSwgFQ1bEdjRwMT3aoadeIF6HMuDRlOxzfXV8ig==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"license": "MIT",
"bin": {
"nanoid": "bin/nanoid.cjs"
"nanoid": "bin/nanoid.js"
},
"engines": {
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
"node": "^18 || >=20"
}
},
"node_modules/natural-compare": {
@@ -4833,6 +4833,23 @@
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
"license": "MIT"
},
"node_modules/postcss/node_modules/nanoid": {
"version": "3.3.7",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz",
"integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"bin": {
"nanoid": "bin/nanoid.cjs"
},
"engines": {
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",

View File

@@ -24,6 +24,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"lucide-react": "^0.290.0",
"nanoid": "^5.0.4",
"next": "^14.0.4",
"next-plausible": "^3.12.0",
"next-themes": "^0.2.1",

View File

@@ -1,9 +1,10 @@
import { getPrisma } from '@/lib/prisma'
import { ExpenseFormValues, GroupFormValues } from '@/lib/schemas'
import { Expense } from '@prisma/client'
import { nanoid } from 'nanoid'
export function randomId() {
return Math.random().toString(36).slice(2, 9)
return nanoid()
}
export async function createGroup(groupFormValues: GroupFormValues) {