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.

fix hashToken

Steven Tey006039394bf6
diff --git a/apps/web/app/api/admin/impersonate/route.ts b/apps/web/app/api/admin/impersonate/route.ts
index 2335ffc980..a0ad13f2c7 100644
--- a/apps/web/app/api/admin/impersonate/route.ts
+++ b/apps/web/app/api/admin/impersonate/route.ts
@@ -90,7 +90,7 @@ async function getImpersonateUrl(email: string) {
await prisma.verificationToken.create({
data: {
identifier: email,
- token: hashToken(token),
+ token: await hashToken(token),
expires: new Date(Date.now() + 60000),
},
});
diff --git a/apps/web/app/api/user/tokens/route.ts b/apps/web/app/api/user/tokens/route.ts
index a17dd17217..5b6c799084 100644
--- a/apps/web/app/api/user/tokens/route.ts
+++ b/apps/web/app/api/user/tokens/route.ts
@@ -33,9 +33,7 @@ export const GET = withSession(async ({ session }) => {
export const POST = withSession(async ({ req, session }) => {
const { name } = await req.json();
const token = nanoid(24);
- const hashedKey = hashToken(token, {
- noSecret: true,
- });
+ const hashedKey = await hashToken(token);
// take first 3 and last 4 characters of the key
const partialKey = `${token.slice(0, 3)}...${token.slice(-4)}`;
await Promise.all([
diff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.ts
index 2566edda88..6f6f724a9c 100644
--- a/apps/web/lib/api/users.ts
+++ b/apps/web/lib/api/users.ts
@@ -43,7 +43,7 @@ export async function inviteUser({
await prisma.verificationToken.create({
data: {
identifier: email,
- token: hashToken(token),
+ token: await hashToken(token, { secret: true }),
expires,
},
});
diff --git a/apps/web/lib/auth/session.ts b/apps/web/lib/auth/session.ts
index 39556ed229..cb5a7efb0e 100644
--- a/apps/web/lib/auth/session.ts
+++ b/apps/web/lib/auth/session.ts
@@ -2,7 +2,8 @@ import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
import { prisma } from "@/lib/prisma";
import { getSearchParams } from "@dub/utils";
import { ratelimit } from "../upstash";
-import { Session, getSession, hashToken } from "./utils";
+import { hashToken } from "./hash-token";
+import { Session, getSession } from "./utils";
interface WithSessionHandler {
({
@@ -36,9 +37,7 @@ export const withSession =
}
const apiKey = authorizationHeader.replace("Bearer ", "");
- const hashedKey = hashToken(apiKey, {
- noSecret: true,
- });
+ const hashedKey = await hashToken(apiKey);
const user = await prisma.user.findFirst({
where: {
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index 506f52a84e..05f3b7d3d6 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -10,7 +10,8 @@ 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 { hashToken } from "./hash-token";
+import { Session, getSession } from "./utils";
interface WithWorkspaceHandler {
({
@@ -131,9 +132,7 @@ export const withWorkspace = (
}
if (apiKey) {
- const hashedKey = hashToken(apiKey, {
- noSecret: true,
- });
+ const hashedKey = await hashToken(apiKey);
const user = await prisma.user.findFirst({
where: {
diff --git a/apps/web/lib/cron.ts b/apps/web/lib/cron.ts
index 263ae6782a..d3e8e3c66c 100644
--- a/apps/web/lib/cron.ts
+++ b/apps/web/lib/cron.ts
@@ -1,9 +1,9 @@
+import { prisma } from "@/lib/prisma";
import { Client, Receiver } from "@upstash/qstash";
import Bottleneck from "bottleneck";
import { sendEmail } from "emails";
import ClicksExceeded from "emails/clicks-exceeded";
import LinksLimitAlert from "emails/links-limit";
-import prisma from "./prisma";
import { WorkspaceProps } from "./types";
export const limiter = new Bottleneck({
diff --git a/apps/web/lib/fetchers.ts b/apps/web/lib/fetchers.ts
index e4757f4226..76ececde48 100644
--- a/apps/web/lib/fetchers.ts
+++ b/apps/web/lib/fetchers.ts
@@ -1,6 +1,6 @@
+import { prisma } from "@/lib/prisma";
import { cache } from "react";
import { getSession } from "./auth";
-import prisma from "./prisma";
export const getWorkspaces = cache(async () => {
const session = await getSession();