Skip to content

Commit

Permalink
migrate old personalTeam to personalOrg
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
  • Loading branch information
asutula committed Aug 12, 2024
1 parent 9ce02e6 commit 54932ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/api/src/session-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type SiweFields = Omit<
export interface Auth {
user: schema.User;
personalOrg: schema.Org;
personalTeam?: schema.Org;
}

export interface SessionData {
Expand Down
23 changes: 16 additions & 7 deletions packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { type Store } from "@tableland/studio-store";
import { TRPCError, initTRPC } from "@trpc/server";
import superjson from "superjson";
import { ZodError, z } from "zod";
import { getIronSession } from "iron-session";
import { type IronSession, getIronSession } from "iron-session";
import { type SessionData, sessionOptions } from "./session-data";

// TODO: the types and interfaces below are from iron-session, but they aren't exported.
Expand Down Expand Up @@ -88,17 +88,26 @@ export const getSession = async function ({
req,
res,
}: GetSessionArgs) {
let session: IronSession<SessionData> | undefined;
if (typeof cookies !== "undefined") {
return await getIronSession<SessionData>(cookies, sessionOptions);
session = await getIronSession<SessionData>(cookies, sessionOptions);
}

if (typeof req !== "undefined" && typeof res !== "undefined") {
return await getIronSession<SessionData>(req, res, sessionOptions);
session = await getIronSession<SessionData>(req, res, sessionOptions);
}
if (!session) {
throw new Error(
"cannot get session from context must supply cookies or req and res",
);
}

throw new Error(
"cannot get session from context must supply cookies or req and res",
);
if (session.auth?.personalTeam) {
session.auth.personalOrg = session.auth.personalTeam;
session.auth.personalTeam = undefined;
await session.save();
}

return session;
};

// get a header from either of the accepted header types
Expand Down

0 comments on commit 54932ef

Please sign in to comment.