Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use secure cookies in local development and fix layout nesting #3949

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/builder/app/env/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const env = {

POSTGREST_URL: process.env.POSTGREST_URL ?? "http://localhost:3000",
POSTGREST_API_KEY: process.env.POSTGREST_API_KEY ?? "",

SECURE_COOKIE:
process.env.SSL === "true" || process.env.NODE_ENV === "production",
};

export type ServerEnv = typeof env;
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/app/services/cookie.server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { createCookie } from "@remix-run/node";
import env from "~/env/env.server";
import { dashboardPath } from "~/shared/router-utils";

export const returnToCookie = createCookie("returnTo", {
path: "/",
httpOnly: true,
sameSite: "lax",
maxAge: 60, // 1 minute because it makes no sense to keep it for a long time
secure: process.env.NODE_ENV === "production",
secure: env.SECURE_COOKIE,
});

export const returnToPath = async (request: Request) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/services/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const sessionStorage = createCookieSessionStorage({
path: "/", // remember to add this so the cookie will work in all routes
httpOnly: true, // for security reasons, make this cookie http only
secrets: env.AUTH_SECRET ? [env.AUTH_SECRET] : undefined, // replace this with an actual secret
secure: process.env.NODE_ENV === "production", // enable this in prod only
secure: env.SECURE_COOKIE,
},
});

Expand Down
Loading