I would personally create a table for this. I would perhaps also add expires_at, and deleted_at columns, to track when it expires (if that is a thing of course) and when it was used/deleted.
What's the best way to send a unique usage code ?
Hello,
The context is the following : a group owner invites another user to join the group and sends this user a code. So when the user connects, he has just to enter the code to join the group.
I need to generate a unique code associated to a unique user and a unique group and this code can be used only once. The question is : where do I store this code ?
I thought about creating another table (group_id, user_id, code) specifically to manage this code and the line will be removed from the database when the user has used the code.
Another way could be to generate a temporary link so that the user can click on this link directly from the email, but would this say that the user is automatically connected by clicking on the link ? For this type of application, I prefer not, I really want that each user manually log in.
Is there a better way to do what I need ?
Thanks for your help.
V
You are actually describing an invitation system. A unique link would be OK and to prevent people are automatically joining the team you can create a landing page for the link that describes the invitation:
You are invited to join Team X by John Doe.
[ Join Team ]
The moment they click the button they are added to the team.
You can create (and expire) the link with Laravel's signed urls: https://laravel.com/docs/9.x/urls#signed-urls or you can keep track of it with a special database table.
Please or to participate in this conversation.