Credits

The kit provides you a way to allocate credits to a user according to the User Plan they have subscribed to. You can then use functions to check, consume, and reset the credits.

Life cycle

Following is the life cycle of the credits that are allocated to a user.

  1. User subscribes to a plan
  2. Credits are allocated to the user as per the plan
  3. Consume credits as per business logic
  4. If the planโ€™s resetType is periodic, the credits are reset periodically.

Set Credits

You can set the credits for a plan in the User Plans. Decide the number of credits based on the business logic.

Check Credits

The User model has a plan field that contains the credits field. This field tells the number of credits that the user has.

Consume Credits

You can consume the credits using the consumeCredits function. This function takes the amount of credits to be consumed and deducts it from the userโ€™s credits.

Reset Credits

If the planโ€™s resetType is periodic, the credits are reset periodically. You can reset the credits using the resetCredits function on demand if required.


MIT 2024 ยฉ Nextra.