Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🐛 Fix broken checkout and portal
Luke Vella502f2a7a43d9
diff --git a/apps/web/src/pages/api/stripe/checkout.ts b/apps/web/src/pages/api/stripe/checkout.tsindex 3369bf71d..c72317107 100644--- a/apps/web/src/pages/api/stripe/checkout.ts+++ b/apps/web/src/pages/api/stripe/checkout.ts@@ -1,10 +1,10 @@-import { getSession } from "@rallly/backend/next/session";import { stripe } from "@rallly/backend/stripe";import { prisma } from "@rallly/database";import { NextApiRequest, NextApiResponse } from "next";import { z } from "zod";import { absoluteUrl } from "@/utils/absolute-url";+import { getServerSession } from "@/utils/auth";export const config = {edge: true,@@ -20,10 +20,10 @@ export default async function handler(req: NextApiRequest,res: NextApiResponse,) {- const userSession = await getSession(req, res);+ const userSession = await getServerSession(req, res);const { period = "monthly", return_path } = inputSchema.parse(req.body);- if (userSession.user?.isGuest !== false) {+ if (!userSession || userSession.user.email === null) {// You need to be logged in to subscriberes.redirect(303,diff --git a/apps/web/src/pages/api/stripe/portal.ts b/apps/web/src/pages/api/stripe/portal.tsindex c440402c0..6e0bf7489 100644--- a/apps/web/src/pages/api/stripe/portal.ts+++ b/apps/web/src/pages/api/stripe/portal.ts@@ -1,10 +1,10 @@-import { getSession } from "@rallly/backend/next/session";import { stripe } from "@rallly/backend/stripe";import { prisma } from "@rallly/database";import { NextApiRequest, NextApiResponse } from "next";import { z } from "zod";import { absoluteUrl } from "@/utils/absolute-url";+import { getServerSession } from "@/utils/auth";const inputSchema = z.object({session_id: z.string().optional(),@@ -15,9 +15,9 @@ export default async function handler(req: NextApiRequest,res: NextApiResponse,) {- const userSession = await getSession(req, res);+ const userSession = await getServerSession(req, res);- if (userSession.user?.isGuest !== false) {+ if (!userSession?.user.email) {// You need to be logged in to subscriberes.status(403)diff --git a/packages/backend/next/index.ts b/packages/backend/next/index.tsindex 80740f5d6..178cd64f8 100644--- a/packages/backend/next/index.ts+++ b/packages/backend/next/index.ts@@ -1,2 +1 @@-export * from "./session";export * from "./utils";diff --git a/packages/backend/next/session.ts b/packages/backend/next/session.tsdeleted file mode 100644index bea7e31c4..000000000--- a/packages/backend/next/session.ts+++ /dev/null@@ -1,17 +0,0 @@-import type { IncomingMessage, ServerResponse } from "http";-import { getIronSession } from "iron-session";-import { withIronSessionApiRoute } from "iron-session/next";-import { NextApiHandler } from "next";--import { sessionConfig } from "../session-config";--export function withSessionRoute(handler: NextApiHandler) {- return withIronSessionApiRoute(handler, sessionConfig);-}--export const getSession = async (- req: Request | IncomingMessage,- res: Response | ServerResponse,-) => {- return getIronSession(req, res, sessionConfig);-};