mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 10:16:32 +02:00
🐛 Fix broken checkout and portal
This commit is contained in:
parent
703d551aac
commit
502f2a7a43
4 changed files with 6 additions and 24 deletions
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
export * from "./session";
|
||||
export * from "./utils";
|
||||
|
|
|
@ -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);
|
||||
};
|
Loading…
Add table
Reference in a new issue