This is one way to do it. But now that we know that @debemghf is not actually seeking to delete a User (which, again, there’s no good reason for us to do except when the user themselves requests it), but is actually seeking to understand HOW they can have a concept of a “subscribed” User and enforce a subscription expiry, we have a lot more options.
The question here is not really, how do I delete the User after some time period. The question is more basic:
How do we control access to subscribers-only page?
First, what does it mean to have a user subscribed to some service we provide? They’ve taken some action (like paying us maybe) that grants them access to some feature or service.
So, when they take that action, we need to record that. We can, of course, create a Subscription object (if our site/services are complex and there are different things or tiers that a user might subscribe to) and attach it to the user. Or, if our site/service is simple, we might just record that event on the User record.
What should we record? The only thing we must record is an expiry date (this should be an actual date object, a date/time). Let’s assume the simplest case where we only offer one type of subscription. We can have a field, of date type on the User object. Let’s call it “Sub Expiry Date”.
When the user “subscribes”, we record this event by setting the value of User’s Sub Expiry Date to the date/time that the subscription expires. For example, for a 30 day subscription: Make changes to User, field “Sub Expiry Date” = Current Date/Time +(days)30.
Once we have this, we can always, at any time, detect whether the User is “subscribed”. And we can detect 3 unique states:
-
The User has never subscribed: If User’s Sub Expiry Date is empty
-
The User has an active subscription: If User’s Sub Expiry Date is not empty AND Current Date/Time < User’s Sub Expiry Date is true
-
The User has an expired subscription: If User’s Sub Expiry Date is not empty AND Current Date/Time < User’s Sub Expiry Date is false
Note that we do not need access to API Workflows or to expend any server-side resources to check this. (Now, perhaps we should, but we do not have to.) When the user shows up to our site and logs in or tries to go to some valuable (subscribers-only) page, we simply check this one condition:
Current User's Sub Expiry Date is not empty and Current Date/Time < User's Sub Expiry Date
What do we do on our subscribers-only page to control access?
In the case of a subscribers-only page: All elements on this page should be hidden unless this condition is true. So, just like any “admin”, or “Logged-in User-only”, or other “controlled access” page, we design the page such that all elements are hidden by default. (Typically, by grouping all of those elements in a group so we only have to unhide/show one thing.)
Then, we have at least one Workflow on the page that fires on “When page is loaded” with the “Only when” condition Current User's Sub Expiry Date is not empty and Current Date/Time < User's Sub Expiry Date
. This is the “hooray, you’re a subscriber!” workflow. So we can show the hidden group. (Element > Show > the hidden group) And now the User goes on about their business on the page.
If a User does not meet this condition, they will just be stuck here on a blank page, unless we do something else. So, we can for example:
Handle the case of a User who has never subscribed: We need another When Page is Loaded Workflow, this one “Only when” Current User's Sub Expiry Date is empty
. We can display an alert (“You must be a subscriber to view this page.”), show a pop-up (“Hey, subscribe today to get this amazing content!”, and/or redirect the User to a tout page for our service (Navigate > Go to page > our awesome tout page).
Handle the case of the User with an expired subscription: We need another When Page is Loaded Workflow, this one “Only when” Current User's Sub Expiry Date is not empty and Current Date/Time > Current User's Sub Expiry Date
. We can do whatever we need here, like navigate the User to a subscription renewal page. We could get fancy if we want. Perhaps if the sub has only recently expired, we might show a nag pop-up, but let them get to the content anyway.
But eventually, we want to get them to re-up their subscription, right? When they do that, we update the Sub Expiry Date field to the new expiry date.
And there you go.
I have more to say about what we SHOULD schedule vis-a-vis subscriptions, but maybe that’s better for a video…