Files
triggerdotdev--trigger.dev/apps/webapp/app/services/currentProject.server.ts
Matt Aitken 29edcd3df9
🚀 Publish Trigger.dev Docker / units (push) Failing after 0s
🚀 Publish Trigger.dev Docker / e2e (push) Failing after 0s
🚀 Publish Trigger.dev Docker / typecheck (push) Failing after 4s
🚀 Publish Trigger.dev Docker / publish (push) Has been skipped
Rename and delete projects (#880)
* Side menu: selector title changed to project. Changed section headers and made it Slack + Discord

* Added project settings page. Renaming is working

* Added project.deletedAt column

* Deleting projects WIP

* Allow clearing the project from the session

* Don’t load projects that are deleted

* Improved the project selection logic

* Clear the session project id when deleting a project

* Deleting the last project in an org now works. The new project page doesn’t have the sidebar anymore.

* Removed false code comment

* Added the JobRun index back in, using Prisma. Otherwise it tries to remove it on each migration

* Only return environments where the project isn’t deleted. This will block API calls

* Do the project deletedAt check in code, not SQL

* Made it clearer what the code does with a comment and applied the same logic to the public api key
2024-02-05 13:14:33 +00:00

40 lines
1.4 KiB
TypeScript

import { Session, createCookieSessionStorage } from "@remix-run/node";
import { env } from "~/env.server";
export const currentProjectSessionStorage = createCookieSessionStorage({
cookie: {
name: "__project", // use any name you want here
sameSite: "lax", // this helps with CSRF
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.SESSION_SECRET],
secure: env.NODE_ENV === "production", // enable this in prod only
maxAge: 60 * 60 * 365, // 1 year
},
});
function getCurrentProjectSession(request: Request) {
return currentProjectSessionStorage.getSession(request.headers.get("Cookie"));
}
export function commitCurrentProjectSession(session: Session) {
return currentProjectSessionStorage.commitSession(session);
}
export async function getCurrentProjectId(request: Request): Promise<string | undefined> {
const session = await getCurrentProjectSession(request);
return session.get("currentProjectId");
}
export async function setCurrentProjectId(id: string, request: Request) {
const session = await getCurrentProjectSession(request);
session.set("currentProjectId", id);
return session;
}
export async function clearCurrentProjectId(request: Request) {
const session = await getCurrentProjectSession(request);
session.unset("currentProjectId");
return session;
}