Files
triggerdotdev--trigger.dev/apps/webapp/app/services/currentOrganization.server.ts
Matt Aitken 9ff4c0dbd5 Project-wide Prettier setup (#237)
* Setup project-wide prettier

* Remove old workspace file

* Remove old debugging directives

* New top-level .prettierignore

* Updated Prettier config settings

* Contrubuting guide: Fix for some bad code blocks

* Added more ignores

* Improved the format script command

* printWidth set to 100

* Formatted entire repo (pnpm run format)
2023-08-01 10:21:22 +01:00

45 lines
1.3 KiB
TypeScript

import { createCookieSessionStorage, Session } from "@remix-run/node";
import { env } from "~/env.server";
export const currentOrgSessionStorage = createCookieSessionStorage({
cookie: {
name: "__organization", // 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 * 24, // 1 day
},
});
export function getCurrentOrgSession(request: Request) {
return currentOrgSessionStorage.getSession(request.headers.get("Cookie"));
}
export function commitCurrentOrgSession(session: Session) {
return currentOrgSessionStorage.commitSession(session);
}
export async function getCurrentOrg(request: Request): Promise<string | undefined> {
const session = await getCurrentOrgSession(request);
return session.get("currentOrg");
}
export async function setCurrentOrg(slug: string, request: Request) {
const session = await getCurrentOrgSession(request);
session.set("currentOrg", slug);
return session;
}
export async function clearCurrentOrg(request: Request) {
const session = await getCurrentOrgSession(request);
session.unset("currentOrg");
return session;
}