How can I protect a page?

I created a form. After stripe payemnt the user is successfully sent to the form. Unfortunately anyone with the URL can access the form. I want users who have made a stripe payment to be able to access the form and submit one time. Can anyone point me in the right direction? TY in advance, Kelly
1 Reply
kapa.ai
kapa.ai3mo ago
Hi @Kelly Ellie. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Wasp, you can protect a page by setting the authRequired property to true when declaring a page. This ensures that only authenticated users can access the page. Unauthenticated users are redirected to a route defined by the app.auth.onAuthFailedRedirectTo field. Here is an example of how to do it:
page MainPage {
component: import Main from "@src/pages/Main",
authRequired: true
}
page MainPage {
component: import Main from "@src/pages/Main",
authRequired: true
}
This will require an authentication method to be set up in your app. If authRequired is set to true, the page's React component (specified by the component property) receives the user object as a prop. You can read more about the user object in the Accessing the logged-in user section (https://wasp-lang.dev/docs/auth/overview#accessing-the-logged-in-user). However, this will only ensure that the user is authenticated, not that they have made a payment. To ensure that a user has made a payment before accessing the form, you would need to implement additional logic in your application. This could involve checking the user's payment status in your database before rendering the form. Unfortunately, the provided knowledge sources do not contain specific information on how to implement this payment check. You might want to consider asking this question in the Wasp community or checking the Wasp documentation for more information. Source: Wasp Documentation (https://wasp-lang.dev/docs/auth/overview#protecting-a-page-with-authrequired) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kelly Ellie, 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?
Want results from more Discord servers?
Add your server