* move SystemField to features * migrate workflow service * merge two tests for team repository * update imports and migrate team repository * migrate delegation credential repository * migrate credential repository * migrate entityPermissionUtils * migrate hashedLink service and repository * migrate membership service * update imports * remove file * migrate buildEventUrlFromBooking * migrate getAllUserBookings to features * update imports * update organizationMock * migrate slots * migrate date-ranges to schedules dir * migrate getAggregatedAvailability * fix * refactor * migrate useCreateEventType hook to features * migrate assignValueToUser * migrate validateUsername to auth features * migrate system field back to lib * migrate getLabelValueMapFromResponses back to lib * update imports * use relative path * fix type checks * fix * fix * fix tests * update gh codeowners * fix * fix
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import type { GetServerSidePropsContext } from "next";
|
|
import { z } from "zod";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
|
|
|
|
import { btcpayCredentialKeysSchema } from "../../lib/btcpayCredentialKeysSchema";
|
|
|
|
export type IBTCPaySetupProps = z.infer<typeof btcpayCredentialKeysSchema>;
|
|
|
|
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
|
|
try {
|
|
const notFound = { notFound: true } as const;
|
|
if (typeof ctx.params?.slug !== "string") return notFound;
|
|
|
|
const { req } = ctx;
|
|
const session = await getServerSession({ req });
|
|
if (!session?.user?.id) return { redirect: { permanent: false, destination: "/auth/login" } };
|
|
|
|
const credential = await CredentialRepository.findFirstByUserIdAndType({
|
|
userId: session.user.id,
|
|
type: "btcpayserver_payment",
|
|
});
|
|
|
|
let props: IBTCPaySetupProps | undefined;
|
|
if (credential?.key) {
|
|
const keyParsing = btcpayCredentialKeysSchema.safeParse(credential.key);
|
|
if (keyParsing.success) {
|
|
props = keyParsing.data;
|
|
}
|
|
}
|
|
return { props: props ?? {} };
|
|
} catch (error) {
|
|
return {
|
|
props: {},
|
|
};
|
|
}
|
|
};
|