29edcd3df9
* 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
40 lines
1.4 KiB
TypeScript
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;
|
|
}
|