Use crypto-random-string

This commit is contained in:
David Corbitt
2023-08-08 11:45:03 -07:00
parent ae7acbfdd4
commit ea91d692d3
3 changed files with 19 additions and 9 deletions

View File

@@ -1,11 +1,5 @@
import cryptoRandomString from "crypto-random-string";
const KEY_LENGTH = 42;
export const generateApiKey = () => {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let randomChars = "";
for (let i = 0; i < KEY_LENGTH; i++) {
randomChars += chars.charAt(Math.floor(Math.random() * chars.length));
}
return `opc_${randomChars}`;
};
export const generateApiKey = () => `opc_${cryptoRandomString({ length: KEY_LENGTH })}`;