🐛 Fix broken checkout and portal

This commit is contained in:
Luke Vella 2023-10-20 12:10:34 +01:00
parent 703d551aac
commit 502f2a7a43
4 changed files with 6 additions and 24 deletions

View file

@ -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 subscribe
res.redirect(
303,

View file

@ -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 subscribe
res
.status(403)

View file

@ -1,2 +1 @@
export * from "./session";
export * from "./utils";

View file

@ -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);
};