Use crypto-random-string
This commit is contained in:
@@ -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 })}`;
|
||||
|
||||
Reference in New Issue
Block a user