The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
move hashToken to hash.ts
Kiran Ke3dec34fd7f2
diff --git a/apps/web/app/api/admin/impersonate/route.ts b/apps/web/app/api/admin/impersonate/route.tsindex d4c22412ba..a0ee58f01f 100644--- a/apps/web/app/api/admin/impersonate/route.ts+++ b/apps/web/app/api/admin/impersonate/route.ts@@ -1,4 +1,5 @@-import { hashToken, withAdmin } from "@/lib/auth";+import { withAdmin } from "@/lib/auth";+import { hashToken } from "@/lib/auth/hash";import prisma from "@/lib/prisma";import { DUB_DOMAINS_ARRAY } from "@dub/utils";import { randomBytes } from "crypto";diff --git a/apps/web/app/api/user/tokens/route.ts b/apps/web/app/api/user/tokens/route.tsindex 39a906b7e2..486397a3e0 100644--- a/apps/web/app/api/user/tokens/route.ts+++ b/apps/web/app/api/user/tokens/route.ts@@ -1,4 +1,5 @@-import { hashToken, withSession } from "@/lib/auth";+import { withSession } from "@/lib/auth";+import { hashToken } from "@/lib/auth/hash";import { qstash } from "@/lib/cron";import prisma from "@/lib/prisma";import { APP_DOMAIN_WITH_NGROK, nanoid } from "@dub/utils";diff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.tsindex b65661fb9c..dd11015076 100644--- a/apps/web/lib/api/users.ts+++ b/apps/web/lib/api/users.ts@@ -1,4 +1,5 @@-import { Session, hashToken } from "@/lib/auth";+import { Session } from "@/lib/auth";+import { hashToken } from "@/lib/auth/hash";import prisma from "@/lib/prisma";import { WorkspaceProps } from "@/lib/types";import { TWO_WEEKS_IN_SECONDS } from "@dub/utils";diff --git a/apps/web/lib/auth/hash.ts b/apps/web/lib/auth/hash.tsnew file mode 100644index 0000000000..acbd622e47--- /dev/null+++ b/apps/web/lib/auth/hash.ts@@ -0,0 +1,14 @@+import { createHash } from "crypto";++export const hashToken = (+ token: string,+ {+ noSecret = false,+ }: {+ noSecret?: boolean;+ } = {},+) => {+ return createHash("sha256")+ .update(`${token}${noSecret ? "" : process.env.NEXTAUTH_SECRET}`)+ .digest("hex");+};diff --git a/apps/web/lib/auth/session.ts b/apps/web/lib/auth/session.tsindex 3e0bc079a1..07563a5bcc 100644--- a/apps/web/lib/auth/session.ts+++ b/apps/web/lib/auth/session.ts@@ -1,8 +1,9 @@import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";+import { hashToken } from "@/lib/auth/hash";import prisma from "@/lib/prisma";import { getSearchParams } from "@dub/utils";import { ratelimit } from "../upstash";-import { Session, getSession, hashToken } from "./utils";+import { Session, getSession } from "./utils";export interface WithSessionHandler {({diff --git a/apps/web/lib/auth/utils.ts b/apps/web/lib/auth/utils.tsindex 215fef07fd..4de897b43d 100644--- a/apps/web/lib/auth/utils.ts+++ b/apps/web/lib/auth/utils.ts@@ -1,4 +1,3 @@-import { createHash } from "crypto";import { getServerSession } from "next-auth/next";import { authOptions } from "./options";@@ -14,16 +13,3 @@ export interface Session {export const getSession = async () => {return getServerSession(authOptions) as Promise<Session>;};--export const hashToken = (- token: string,- {- noSecret = false,- }: {- noSecret?: boolean;- } = {},-) => {- return createHash("sha256")- .update(`${token}${noSecret ? "" : process.env.NEXTAUTH_SECRET}`)- .digest("hex");-};diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.tsindex f800788a7f..4783052077 100644--- a/apps/web/lib/auth/workspace.ts+++ b/apps/web/lib/auth/workspace.ts@@ -1,4 +1,5 @@import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";+import { hashToken } from "@/lib/auth/hash";import prisma from "@/lib/prisma";import {API_DOMAIN,@@ -10,7 +11,7 @@ import { Link as LinkProps } from "@prisma/client";import { exceededLimitError } from "../api/errors";import { PlanProps, WorkspaceProps } from "../types";import { ratelimit } from "../upstash";-import { Session, getSession, hashToken } from "./utils";+import { Session, getSession } from "./utils";interface WithWorkspaceHandler {({diff --git a/packages/ui/src/nav-logo.tsx b/packages/ui/src/nav-logo.tsxindex 5deca072e8..4446a9903f 100644--- a/packages/ui/src/nav-logo.tsx+++ b/packages/ui/src/nav-logo.tsx@@ -83,7 +83,7 @@ export function NavLogo({setIsPopoverOpen(false);}}>- <div className="grid gap-1 rounded-lg border border-gray-200 bg-white p-2 drop-shadow-sm sm:min-w-[240px] dark:border-white/[0.15] dark:bg-black">+ <div className="grid gap-1 rounded-lg border border-gray-200 bg-white p-2 drop-shadow-sm dark:border-white/[0.15] dark:bg-black sm:min-w-[240px]"><ContextMenuButtontext="Copy Logo as SVG"variant="outline"diff --git a/packages/ui/src/nav-mobile.tsx b/packages/ui/src/nav-mobile.tsxindex db599fa414..f58b70be88 100644--- a/packages/ui/src/nav-mobile.tsx+++ b/packages/ui/src/nav-mobile.tsx@@ -35,7 +35,7 @@ export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {<buttononClick={() => setOpen(!open)}className={cn(- "fixed right-3 top-3 z-40 rounded-full p-2 transition-colors duration-200 hover:bg-gray-200 focus:outline-none active:bg-gray-300 lg:hidden dark:hover:bg-white/20 dark:active:bg-white/30",+ "fixed right-3 top-3 z-40 rounded-full p-2 transition-colors duration-200 hover:bg-gray-200 focus:outline-none active:bg-gray-300 dark:hover:bg-white/20 dark:active:bg-white/30 lg:hidden",open && "hover:bg-gray-100 active:bg-gray-200",)}>@@ -47,7 +47,7 @@ export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {</button><navclassName={cn(- "fixed inset-0 z-20 hidden w-full bg-white px-5 py-16 lg:hidden dark:bg-black dark:text-white/70",+ "fixed inset-0 z-20 hidden w-full bg-white px-5 py-16 dark:bg-black dark:text-white/70 lg:hidden",open && "block",)}>