Hello!
I have a question / feature request for ActiveRecord::SignedId. I already built classic invitation system with it, the invitation logic looks like this:
# Generate the signed id and send it via email
Account.first.signed_id(expires_in: 1.week, purpose: :invitation)
I would now like to add a role to this invitation such as admin, manager, user. I don’t think there is a way to do this with signed ids yet. I would love to make a PR and add it to Rails if you find it interresting!
Would it make sense to do something like this:
# Generate an invitation to the account with the admin role
Account.first.signed_id(expires_in: 1.week, purpose: :invitation, payload: :admin)
# Retrieve the account and the payload
account, payload = Account.find_signed(
Account.first.signed_id(expires_in: 1.week, purpose: :invitation, payload: :admin),
extract_payload: true
)
The payload could be passed in the message something like “#{id}–#{payload}”. Does it make sense? Here I chose “–” as a delimiter between the id and the payload but it could be something else.