dokuzbir
Unique Identifier For Session
I have a slot booking app. What i want is lock a slot 5 minutes for a session/user. I added lock_until, locked_for attributes to slots. A user has id, but what is equivalent thing for a session. Also if there are another approaches can you please share?
Marked As Solved
NobbZ
The trick with such identifiers is, that you can use whatever you like and write it into the session…
I’m not experienced with phoenix, but have you considered using it roughly like this?
def create_token() do
uuid = UUID.generate_v4() # you probably need to get a UUID package, therefore this is pseudo code
Phoenix.Token.sign(YourApp.Endpoint, "your secret salt", uuid)
end
def validate_token(token) do
Phoenix.Token.verify(YourApp.Endpoint, "your secret salt", token, max_age: 5 * 60)
end
You can store and retrieve that Token via Plug.Conn.{fetch,get,put}_session.
Also Liked
kokolegorille
There is a slot locking mecanism in this video
around 25 minutes… If this is what You are looking for.
Basically You want to lock a slot for a booking application for 5 minutes? Probably because each booking reduces the capacity of your stock, and You don’t want to sell more than what You can provide.
He wants to lock a timeslot for a user to order something, so no other user could bypass this by typing faster. There is not even the need to store lock_until, just spawn a process with locked_for, and a timeout. As soon as the process expire, so does the lock.
Each resource has a capacity, when You want to book, You request an access, that will decrement capacity, in case You don’t fill the booking in 5 minutes, the token expires without being used, and capacity is increased.
Is that what You want to do?
mgwidmann
I’m not sure what a slot booking app is, could you clarify what you’re trying to do a bit more? Are you trying to ensure a user in a Phoenix application gets logged out every 5 minutes?
Qqwy
Instead of using an UUID, you could use make_ref() |> :erlang.term_to_binary() to create a string-representation of an almost surely unique reference (The keyspace is 2^82), whose behaviour is provided to you by the Erlang VM.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #podcasts
- #code-sync
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








