Skip to content

Commit

Permalink
fix(web): integration cookie retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt committed Aug 29, 2024
1 parent 86b2542 commit d29e448
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions apps/web/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export const authMiddleware: MiddlewareHandler<{
user: UserSession & DefaultSession["user"];
};
}> = async (c, next) => {
const tokenCookie = getCookie(c, "next-auth.session-token");
if (!tokenCookie) return next();
const tokenCookie = getCookie(
c,
env.NODE_ENV === "production"
? "__Secure-next-auth.session-token"
: "next-auth.session-token"
);
if (!tokenCookie) {
return c.json({ error: "Unauthorized" }, { status: 401 });
}
if (!env.NEXTAUTH_SECRET) {
throw new Error("NEXTAUTH_SECRET is not set");
}
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/api/routes/integrations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { zValidator } from "@hono/zod-validator";
import { authMiddleware } from "api/helpers";
import { env } from "env/server.mjs";
import { Hono } from "hono";
import { getGithubApp } from "server/common/github-app";
import type { GithubIntegrationSettings } from "server/common/integrations";
Expand All @@ -24,7 +25,7 @@ export function makeIntegrationsRoute() {
where: { id: projectId, users: { some: { userId: user.id } } },
include: { integrations: true },
});
const referrer = new URL(c.req.header("Referer") ?? "/");
const referrer = new URL(c.req.header("Referer") ?? env.NEXTAUTH_URL);

if (!project) {
referrer.searchParams.set("error", "Unauthorized");
Expand Down

0 comments on commit d29e448

Please sign in to comment.