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.

move hash-token into its own file

Steven Tey62845dc51a33
diff --git a/apps/web/lib/auth/hash-token.ts b/apps/web/lib/auth/hash-token.ts
new file mode 100644
index 0000000000..1d0fa73cd4
--- /dev/null
+++ b/apps/web/lib/auth/hash-token.ts
@@ -0,0 +1,18 @@
+export const hashToken = async (
+ token: string,
+ {
+ secret = false,
+ }: {
+ secret?: boolean;
+ } = {},
+) => {
+ const encoder = new TextEncoder();
+
+ const data = encoder.encode(
+ `${token}${secret ? process.env.NEXTAUTH_SECRET : ""}`,
+ );
+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
+
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
+};
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index 56caca89ac..d0b3e7cfe0 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -1,4 +1,5 @@
export * from "./admin";
+export * from "./hash-token";
export * from "./options";
export * from "./session";
export * from "./utils";
diff --git a/apps/web/lib/auth/session-edge.ts b/apps/web/lib/auth/session-edge.ts
index 959f34640a..7e2b6142fd 100644
--- a/apps/web/lib/auth/session-edge.ts
+++ b/apps/web/lib/auth/session-edge.ts
@@ -1,9 +1,9 @@
import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
-import { hashToken } from "@/lib/auth";
import { getSearchParams } from "@dub/utils";
import { internal_runWithWaitUntil as waitUntil } from "next/dist/server/web/internal-edge-wait-until";
import { getToken, updateTokenLastUsed } from "../planetscale";
import { ratelimit } from "../upstash";
+import { hashToken } from "./hash-token";
import { WithSessionHandler } from "./session";
export const withSessionEdge =
diff --git a/apps/web/lib/auth/utils.ts b/apps/web/lib/auth/utils.ts
index 5264325504..4de897b43d 100644
--- a/apps/web/lib/auth/utils.ts
+++ b/apps/web/lib/auth/utils.ts
@@ -13,22 +13,3 @@ export interface Session {
export const getSession = async () => {
return getServerSession(authOptions) as Promise<Session>;
};
-
-export const hashToken = async (
- token: string,
- {
- secret = false,
- }: {
- secret?: boolean;
- } = {},
-) => {
- const encoder = new TextEncoder();
-
- const data = encoder.encode(
- `${token}${secret ? process.env.NEXTAUTH_SECRET : ""}`,
- );
- const hashBuffer = await crypto.subtle.digest("SHA-256", data);
- const hashArray = Array.from(new Uint8Array(hashBuffer));
-
- return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
-};