Token questions
what are the docs on implementing tokens in opensaas products? how does it work
8 Replies
Hi @ArDev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In OpenSaaS products, tokens, specifically JSON Web Tokens (JWT), are used for user authentication. Here's a brief overview of how it works:
1. When a user logs in, their credentials are sent to the OpenSaaS's authentication API.
2. Upon successful authentication, the API generates a JWT containing the user's username and user ID, signs it with a secret key retrieved from the environment, and sends the token back to the client.
3. The client then stores this token securely and uses it for subsequent API calls to authenticate the user.
Here's a sample code snippet for generating a JWT:
This code is responsible for handling user authentication and JWT creation in a Wasp application. It includes a mock authentication function that, for demonstration purposes, approves any login attempt and assigns a mock user ID.
For more details, you may want to refer to the original discussion on the Wasp Discord server (https://discord.com/channels/686873244791210014/1223328118278983680).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
what are the docs on implementing payment tokens in opensaas products? how does it work
@kapa.ai
Let me check the knowledge base for you. One moment! :books:
----------------------
In OpenSaaS products, Stripe is used for handling payments. The process of implementing a credit system where payments turn into credits involves the following steps:
1. When creating a Stripe product, you can choose a normal one-time payment for a product.
2. When the payment goes through, you give that user a certain amount of credits.
Here's a sample code snippet from the OpenSaaS project that shows how to credit a user with a product payment instead of a subscription:
In this code, the
SUBSCRIPTION_PRICE_ID
is replaced with CREDITS_PRICE_ID
(which you would define in your .env
file), and the subscription purchase logic is replaced with the logic for crediting the user.
For more details, you may want to refer to the original discussion on the Wasp Discord server (https://discord.com/channels/686873244791210014/1205328655300038766).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ArDev, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@Vinny (@Wasp) one for you maybe
hey @ArDev did you read the open saas docs on creating a new (one-time payment) product?
OpenSaaS.sh
Stripe Integration
Open SaaS is a free, open-source, full-stack SaaS starter kit for React + NodeJS.
Once you create the one-time payment credits-based product, you add the product to your environment variables. You can find the configuration for hte plans/products in
src/payment/plans.ts
--> https://github.com/wasp-lang/open-saas/blob/main/template/app/src/payment/plans.ts#L18-L31
At the moment, there is only one credits-based product, and you'll see that it gives the user 10 new credits in the effect.amount
property:
Y
these credits then get deducted every time the user makes a generation on the Demo App (src/demo-ai-app/operations.ts
):
thanks!