bug fixes + improvements
This commit is contained in:
parent
c7cfbc3846
commit
4ee74dc232
|
@ -20,4 +20,5 @@ EMAIL_SERVER=
|
||||||
# Stripe settings (You don't need these, it's for the cloud instance payments)
|
# Stripe settings (You don't need these, it's for the cloud instance payments)
|
||||||
STRIPE_SECRET_KEY=
|
STRIPE_SECRET_KEY=
|
||||||
PRICE_ID=
|
PRICE_ID=
|
||||||
|
TRIAL_PERIOD_DAYS=
|
||||||
NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL=
|
NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL=
|
|
@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faClose } from "@fortawesome/free-solid-svg-icons";
|
import { faClose } from "@fortawesome/free-solid-svg-icons";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import { AccountSettings } from "@/types/global";
|
import { AccountSettings } from "@/types/global";
|
||||||
import { useSession } from "next-auth/react";
|
import { signOut, useSession } from "next-auth/react";
|
||||||
import { resizeImage } from "@/lib/client/resizeImage";
|
import { resizeImage } from "@/lib/client/resizeImage";
|
||||||
import { faPenToSquare } from "@fortawesome/free-regular-svg-icons";
|
import { faPenToSquare } from "@fortawesome/free-regular-svg-icons";
|
||||||
import SubmitButton from "../../SubmitButton";
|
import SubmitButton from "../../SubmitButton";
|
||||||
|
@ -93,6 +93,8 @@ export default function ProfileSettings({
|
||||||
name: user.name,
|
name: user.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
signOut();
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setUser({ ...user, newPassword: undefined });
|
setUser({ ...user, newPassword: undefined });
|
||||||
toggleSettingsModal();
|
toggleSettingsModal();
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import Navbar from "@/components/Navbar";
|
import Navbar from "@/components/Navbar";
|
||||||
import Sidebar from "@/components/Sidebar";
|
import Sidebar from "@/components/Sidebar";
|
||||||
import { ReactNode } from "react";
|
import { ReactNode, useEffect } from "react";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import Loader from "../components/Loader";
|
import Loader from "../components/Loader";
|
||||||
import useRedirect from "@/hooks/useRedirect";
|
import useRedirect from "@/hooks/useRedirect";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import ModalManagement from "@/components/ModalManagement";
|
import ModalManagement from "@/components/ModalManagement";
|
||||||
|
import useModalStore from "@/store/modals";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
|
@ -17,6 +18,14 @@ export default function MainLayout({ children }: Props) {
|
||||||
const redirect = useRedirect();
|
const redirect = useRedirect();
|
||||||
const routeExists = router.route === "/_error" ? false : true;
|
const routeExists = router.route === "/_error" ? false : true;
|
||||||
|
|
||||||
|
const { modal } = useModalStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
modal
|
||||||
|
? (document.body.style.overflow = "hidden")
|
||||||
|
: (document.body.style.overflow = "auto");
|
||||||
|
}, [modal]);
|
||||||
|
|
||||||
if (status === "authenticated" && !redirect && routeExists)
|
if (status === "authenticated" && !redirect && routeExists)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -19,7 +19,10 @@ export default async function checkSubscription(
|
||||||
const isSubscriber = listByEmail.data.some((customer, i) => {
|
const isSubscriber = listByEmail.data.some((customer, i) => {
|
||||||
const hasValidSubscription = customer.subscriptions?.data.some(
|
const hasValidSubscription = customer.subscriptions?.data.some(
|
||||||
(subscription) => {
|
(subscription) => {
|
||||||
const secondsInTwoWeeks = 1209600;
|
const TRIAL_PERIOD_DAYS = process.env.TRIAL_PERIOD_DAYS;
|
||||||
|
const secondsInTwoWeeks = TRIAL_PERIOD_DAYS
|
||||||
|
? Number(TRIAL_PERIOD_DAYS) * 86400
|
||||||
|
: 1209600;
|
||||||
|
|
||||||
subscriptionCanceledAt = subscription.canceled_at;
|
subscriptionCanceledAt = subscription.canceled_at;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ export default async function paymentCheckout(
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
const TRIAL_PERIOD_DAYS = process.env.TRIAL_PERIOD_DAYS;
|
||||||
const session = await stripe.checkout.sessions.create({
|
const session = await stripe.checkout.sessions.create({
|
||||||
customer: isExistingCostomer ? isExistingCostomer : undefined,
|
customer: isExistingCostomer ? isExistingCostomer : undefined,
|
||||||
line_items: [
|
line_items: [
|
||||||
|
@ -65,7 +66,7 @@ export default async function paymentCheckout(
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
subscription_data: {
|
subscription_data: {
|
||||||
trial_period_days: 14,
|
trial_period_days: TRIAL_PERIOD_DAYS ? Number(TRIAL_PERIOD_DAYS) : 14,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,10 @@ export default async function updateCustomerEmail(
|
||||||
const customer = listByEmail.data.find((customer, i) => {
|
const customer = listByEmail.data.find((customer, i) => {
|
||||||
const hasValidSubscription = customer.subscriptions?.data.some(
|
const hasValidSubscription = customer.subscriptions?.data.some(
|
||||||
(subscription) => {
|
(subscription) => {
|
||||||
const secondsInTwoWeeks = 1209600;
|
const TRIAL_PERIOD_DAYS = process.env.TRIAL_PERIOD_DAYS;
|
||||||
|
const secondsInTwoWeeks = TRIAL_PERIOD_DAYS
|
||||||
|
? Number(TRIAL_PERIOD_DAYS) * 86400
|
||||||
|
: 1209600;
|
||||||
|
|
||||||
const isNotCanceledOrHasTime = !(
|
const isNotCanceledOrHasTime = !(
|
||||||
subscription.canceled_at &&
|
subscription.canceled_at &&
|
||||||
|
|
|
@ -93,9 +93,10 @@ export const authOptions: AuthOptions = {
|
||||||
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
||||||
const PRICE_ID = process.env.PRICE_ID;
|
const PRICE_ID = process.env.PRICE_ID;
|
||||||
|
|
||||||
console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa", token);
|
const TRIAL_PERIOD_DAYS = process.env.TRIAL_PERIOD_DAYS;
|
||||||
|
const secondsInTwoWeeks = TRIAL_PERIOD_DAYS
|
||||||
const secondsInTwoWeeks = 1209600;
|
? Number(TRIAL_PERIOD_DAYS) * 86400
|
||||||
|
: 1209600;
|
||||||
const subscriptionIsTimesUp =
|
const subscriptionIsTimesUp =
|
||||||
token.subscriptionCanceledAt &&
|
token.subscriptionCanceledAt &&
|
||||||
new Date() >
|
new Date() >
|
||||||
|
@ -104,7 +105,11 @@ export const authOptions: AuthOptions = {
|
||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
|
|
||||||
if (STRIPE_SECRET_KEY && PRICE_ID && (trigger || subscriptionIsTimesUp)) {
|
if (
|
||||||
|
STRIPE_SECRET_KEY &&
|
||||||
|
PRICE_ID &&
|
||||||
|
(trigger || subscriptionIsTimesUp || !token.isSubscriber)
|
||||||
|
) {
|
||||||
console.log("EXECUTED!!!");
|
console.log("EXECUTED!!!");
|
||||||
const subscription = await checkSubscription(
|
const subscription = await checkSubscription(
|
||||||
STRIPE_SECRET_KEY,
|
STRIPE_SECRET_KEY,
|
||||||
|
|
|
@ -77,11 +77,7 @@ export default function Register() {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
if (form.email) await sendConfirmation();
|
if (form.email) await sendConfirmation();
|
||||||
|
|
||||||
toast.success(
|
toast.success("User Created!");
|
||||||
emailEnabled
|
|
||||||
? "User Created! Please check you email."
|
|
||||||
: "User Created!"
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
toast.error(data.response);
|
toast.error(data.response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ declare global {
|
||||||
STRIPE_SECRET_KEY?: string;
|
STRIPE_SECRET_KEY?: string;
|
||||||
PRICE_ID?: string;
|
PRICE_ID?: string;
|
||||||
NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL?: string;
|
NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL?: string;
|
||||||
|
TRIAL_PERIOD_DAYS?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue