cesargb / laravel-magiclink

Create link for authenticate in Laravel without password or get private content
MIT License
359 stars 43 forks source link

[QUESTION] How to overwrite or extend middleware #42

Closed LarryBarker closed 2 years ago

LarryBarker commented 2 years ago

Hello, thank you for sharing this package. I have a question about extending the behavior of the middleware. Let me explain our use case:

  1. We use magic links to provide users with a link to create their profile
  2. After their profile is created, if they use the magic link again, it should take them to the dashboard

Our problem is that after the profile is created, when a user clicks the magic link again, they are redirected to the profile screen. This is a problem because it opens a security loop where someone can reset the password.

We have tried creating our own middleware to handle the check and redirect to the dashboard. However, in all cases, the user is redirected to the profile screen (this is the original redirect route when the magic link is created).

Is it possible to extend the middleware provided by the package? If not, would it be better to use events for this use case? If so, how are events used in this package?

Lastly, if there is a better solution, what would you recommend?

Thank you :)

cesargb commented 2 years ago

Hello @LarryBarker,

If I have not misunderstood you, you need the link, once the profile is used and activated, to be disabled.

In this case, you can create the link by assigning the value 1 to the third argument.

$numMaxVisits = 1; // Only can visit one time

$magiclink = MagicLink::create(new ResponseAction(), null, $numMaxVisits);

This link will only use one time.

Please let me know if this would help you.

LarryBarker commented 2 years ago

Thanks for the quick reply. I appreciate your input. Our use case is a little different though.

We actually allow a max number of visits to be 3. Our thought is that if someone uses the link once but doesn't complete their profile, they can use it again.

I think this is what our real issue is.

cesargb commented 2 years ago

Now I understand the logic. I have just published a PR that I think may suit your needs. #43

With this feature, do you think it can help you?

LarryBarker commented 2 years ago

Interesting... thank you for your prompt feedback! I've shared this with my colleague for review, will let you know how it goes.