This episode is for members only

Sign up to access "Build a Pay Once For Access App" right now.

Get started
Already a member? Sign in to continue
Playing
13. Protecting the payment page with middleware

Transcript

00:00
This isn't strictly necessary but it would be really nice to prevent an already paid user from accessing this payment page again.
00:09
So ideally we wouldn't want them to pay twice for this, we wouldn't want them to land on this page. So what we're actually going to do is we're going to create, if we come over to our middleware, an opposite method to redirect if not member
00:23
and we're going to go ahead and create a piece of middleware to redirect to user if they are a member. So if we come over to our terminal here and just create out some more middleware, let's call this redirect if member and what we can do is pretty much grab this here and do the same thing over and redirect if member but if they are a member
00:50
we're going to redirect them over to the dashboard or we could redirect them to the members page. So let's go over to our payment index controller and we already have our middleware up here for auth, we're also going to use redirect if member, there we go, and now if we are a member we just get redirected on that payments page so we can't make another payment.

Episode summary

In this episode, we're taking a closer look at protecting your payment page from users who have already paid. The idea is pretty straightforward: you don't want someone who's already a member to accidentally pay again!

We'll walk through creating a new middleware called redirectIfMember. This middleware checks if the user is already a member, and if they are, it automatically redirects them away from the payment page (like sending them to the dashboard or a members area). That way, only users who actually need to pay can access the payment page.

You'll see how to set up the middleware, add it to your payment controller, and confirm that everything is working as expected. It's a simple way to give your users a smoother experience and protect them from double charges.

Episode discussion

No comments, yet. Be the first!