@roam-garden/landscaping-toolbox
Version:
Common UI things for Roam Garden management
33 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.currentUserHasValidSubscription = exports.hasValidSubscription = exports.getSubscriptionAttribute = void 0;
const aws_amplify_1 = require("aws-amplify");
const StripeAttributes = {
subscriptionEnd: "custom:StripeSubEnd",
};
const getUserAttributes = (user) => new Promise(((resolve, reject) => {
user.getUserAttributes((err, data) => {
if (err !== null)
reject(err);
else
resolve(data);
});
}));
async function getSubscriptionAttribute(user) {
const attrs = await getUserAttributes(user);
return attrs === null || attrs === void 0 ? void 0 : attrs.find(it => it.getName() === StripeAttributes.subscriptionEnd);
}
exports.getSubscriptionAttribute = getSubscriptionAttribute;
const hasValidSubscription = async (user) => {
const endDate = await getSubscriptionAttribute(user);
if (!endDate)
return false;
return new Date(endDate.getValue()) > new Date();
};
exports.hasValidSubscription = hasValidSubscription;
const currentUserHasValidSubscription = async () => {
const user = await aws_amplify_1.Auth.currentAuthenticatedUser();
return exports.hasValidSubscription(user);
};
exports.currentUserHasValidSubscription = currentUserHasValidSubscription;
//# sourceMappingURL=billing.js.map