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_SECRET_KEY=
|
||||
PRICE_ID=
|
||||
TRIAL_PERIOD_DAYS=
|
||||
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 useAccountStore from "@/store/account";
|
||||
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 { faPenToSquare } from "@fortawesome/free-regular-svg-icons";
|
||||
import SubmitButton from "../../SubmitButton";
|
||||
|
@ -93,6 +93,8 @@ export default function ProfileSettings({
|
|||
name: user.name,
|
||||
});
|
||||
|
||||
signOut();
|
||||
|
||||
if (response.ok) {
|
||||
setUser({ ...user, newPassword: undefined });
|
||||
toggleSettingsModal();
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import Navbar from "@/components/Navbar";
|
||||
import Sidebar from "@/components/Sidebar";
|
||||
import { ReactNode } from "react";
|
||||
import { ReactNode, useEffect } from "react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import Loader from "../components/Loader";
|
||||
import useRedirect from "@/hooks/useRedirect";
|
||||
import { useRouter } from "next/router";
|
||||
import ModalManagement from "@/components/ModalManagement";
|
||||
import useModalStore from "@/store/modals";
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
|
@ -17,6 +18,14 @@ export default function MainLayout({ children }: Props) {
|
|||
const redirect = useRedirect();
|
||||
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)
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -19,7 +19,10 @@ export default async function checkSubscription(
|
|||
const isSubscriber = listByEmail.data.some((customer, i) => {
|
||||
const hasValidSubscription = customer.subscriptions?.data.some(
|
||||
(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;
|
||||
|
||||
|
|
|
@ -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({
|
||||
customer: isExistingCostomer ? isExistingCostomer : undefined,
|
||||
line_items: [
|
||||
|
@ -65,7 +66,7 @@ export default async function paymentCheckout(
|
|||
enabled: true,
|
||||
},
|
||||
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 hasValidSubscription = customer.subscriptions?.data.some(
|
||||
(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 = !(
|
||||
subscription.canceled_at &&
|
||||
|
|
|
@ -93,9 +93,10 @@ export const authOptions: AuthOptions = {
|
|||
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
||||
const PRICE_ID = process.env.PRICE_ID;
|
||||
|
||||
console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa", token);
|
||||
|
||||
const secondsInTwoWeeks = 1209600;
|
||||
const TRIAL_PERIOD_DAYS = process.env.TRIAL_PERIOD_DAYS;
|
||||
const secondsInTwoWeeks = TRIAL_PERIOD_DAYS
|
||||
? Number(TRIAL_PERIOD_DAYS) * 86400
|
||||
: 1209600;
|
||||
const subscriptionIsTimesUp =
|
||||
token.subscriptionCanceledAt &&
|
||||
new Date() >
|
||||
|
@ -104,7 +105,11 @@ export const authOptions: AuthOptions = {
|
|||
1000
|
||||
);
|
||||
|
||||
if (STRIPE_SECRET_KEY && PRICE_ID && (trigger || subscriptionIsTimesUp)) {
|
||||
if (
|
||||
STRIPE_SECRET_KEY &&
|
||||
PRICE_ID &&
|
||||
(trigger || subscriptionIsTimesUp || !token.isSubscriber)
|
||||
) {
|
||||
console.log("EXECUTED!!!");
|
||||
const subscription = await checkSubscription(
|
||||
STRIPE_SECRET_KEY,
|
||||
|
|
|
@ -77,11 +77,7 @@ export default function Register() {
|
|||
if (response.ok) {
|
||||
if (form.email) await sendConfirmation();
|
||||
|
||||
toast.success(
|
||||
emailEnabled
|
||||
? "User Created! Please check you email."
|
||||
: "User Created!"
|
||||
);
|
||||
toast.success("User Created!");
|
||||
} else {
|
||||
toast.error(data.response);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ declare global {
|
|||
STRIPE_SECRET_KEY?: string;
|
||||
PRICE_ID?: string;
|
||||
NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL?: string;
|
||||
TRIAL_PERIOD_DAYS?: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ŝarĝante…
Reference in New Issue