Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

use randomBytes to create tokens

Kiran Kfa7961ee1cea
diff --git a/apps/web/lib/api/oauth/utils.ts b/apps/web/lib/api/oauth/utils.ts
index 89f2fc1b69..1ae5fb2c42 100644
--- a/apps/web/lib/api/oauth/utils.ts
+++ b/apps/web/lib/api/oauth/utils.ts
@@ -1,4 +1,4 @@
-import { nanoid } from "ai";
+import { randomBytes } from "crypto";
export const generateCodeChallengeHash = async (codeVerifier: string) => {
const encoder = new TextEncoder();
@@ -6,13 +6,12 @@ export const generateCodeChallengeHash = async (codeVerifier: string) => {
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const base64url = hashArray.map((byte) => String.fromCharCode(byte)).join("");
- const hashBase64 = Buffer.from(base64url, "binary")
+
+ return Buffer.from(base64url, "binary")
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
-
- return hashBase64;
};
export const createToken = ({
@@ -22,5 +21,5 @@ export const createToken = ({
prefix?: string;
length: number;
}) => {
- return `${prefix || ""}${nanoid(length)}`;
+ return `${prefix || ""}${randomBytes(length).toString("hex")}`;
};