Phoenix.Token

Phoenix built-in generate and verify signed tokens(not encrypted, so can verify data was signed not hide data)

user_id = 1
token = Phoenix.Token.sign(ReactPhoenixWeb.Endpoint, "user auth", user_id)
Phoenix.Token.verify(ReactPhoenixWeb.Endpoint, "user auth", token, max_age: 86400) #{:ok, 1}

Arg 1: Uses the secret key base configured in the endpoint

Arg 2: cryptographic salt, kinda like a namespace

^Must be same in sign and verify

Arg 3: What to codify in the string

Extra

Also has encrypt and decrypt

Last updated