Skip to content

Commit 2f584be

Browse files
committed
Clean docs and change var name
1 parent c90e6d1 commit 2f584be

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

lib/extensions/persistent_session/plug/cookie.ex

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ defmodule PowPersistentSession.Plug.Cookie do
33
This plug will handle persistent user sessions with cookies.
44
55
By default, the cookie will expire after 30 days. The cookie expiration will
6-
be renewed on every request. The token in the cookie can only be used once to
7-
create a session.
6+
be renewed on every request where a user is assigned to the conn. The token
7+
in the cookie can only be used once to create a session.
88
99
If an assigned private `:pow_session_metadata` key exists in the conn with a
1010
keyword list containing a `:fingerprint` key, that fingerprint value will be
@@ -41,9 +41,9 @@ defmodule PowPersistentSession.Plug.Cookie do
4141
`[max_age: max_age, path: "/"]` where `:max_age` is the value defined in
4242
`:persistent_session_ttl`.
4343
44-
* `:persistent_session_cookie_expiration_drift` - integer value in seconds
45-
for how much time till the cookie should expire after the token has been
46-
fetched in `authenticate/2`. Defaults to 10.
44+
* `:persistent_session_cookie_expiration_timeout` - integer value in
45+
seconds for how much time should go by before cookie should expire after
46+
the token is fetched in `authenticate/2`. Defaults to 10.
4747
4848
## Custom metadata
4949
@@ -75,7 +75,7 @@ defmodule PowPersistentSession.Plug.Cookie do
7575
alias Pow.{Config, Plug, UUID}
7676

7777
@cookie_key "persistent_session_cookie"
78-
@cookie_expiration_drift 10
78+
@cookie_expiration_timeout 10
7979

8080
@doc """
8181
Sets a persistent session cookie with an auto generated token.
@@ -141,8 +141,8 @@ defmodule PowPersistentSession.Plug.Cookie do
141141
@doc """
142142
Expires the persistent session cookie.
143143
144-
If a persistent session cookie exists it'll be expired, and the token in
145-
the persistent session cache will be deleted.
144+
If a persistent session cookie exists it'll be updated to expire immediately,
145+
and the token in the persistent session cache will be deleted.
146146
"""
147147
@spec delete(Conn.t(), Config.t()) :: Conn.t()
148148
def delete(conn, config) do
@@ -177,16 +177,24 @@ defmodule PowPersistentSession.Plug.Cookie do
177177
Authenticates a user with the persistent session cookie.
178178
179179
If a persistent session cookie exists, it'll fetch the credentials from the
180-
persistent session cache, and create a new session and persistent session
181-
cookie. The max age of the old cookie will always be updated to the value of
182-
`:persistent_session_cookie_expiration_drift` to prevent eager expiration in
183-
case of multiple simultaneous requests.
180+
persistent session cache.
181+
182+
After the value is fetched from the cookie, it'll be updated to expire after
183+
the value of `:persistent_session_cookie_expiration_timeout` so invalid
184+
cookies will be deleted eventually. This timeout prevents immediate deletion
185+
of the cookie so in case of multiple simultaneous requests, the cache has
186+
time to update the value.
187+
188+
If credentials was fetched successfully, the token in the cache is deleted, a
189+
new session is created, and `create/2` is called to create a new persistent
190+
session cookie. This will override any expiring cookie.
184191
185192
If a `:session_metadata` keyword list is fetched from the persistent session
186193
metadata, all the values will be merged into the private
187194
`:pow_session_metadata` key in the conn.
188195
189-
If there is a user assigned in the conn, the cookie expiration will be renewed.
196+
The expiration date for the cookie will be reset on each request where a user
197+
is assigned to the conn.
190198
"""
191199
@spec authenticate(Conn.t(), Config.t()) :: Conn.t()
192200
def authenticate(conn, config) do
@@ -226,7 +234,7 @@ defmodule PowPersistentSession.Plug.Cookie do
226234
end
227235

228236
defp expire_cookie(conn, cookie_key, key_id, config) do
229-
max_age = Config.get(config, :persistent_session_cookie_expiration_drift, @cookie_expiration_drift)
237+
max_age = Config.get(config, :persistent_session_cookie_expiration_timeout, @cookie_expiration_timeout)
230238
opts =
231239
config
232240
|> cookie_opts()

test/extensions/persistent_session/plug/cookie_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ defmodule PowPersistentSession.Plug.CookieTest do
144144
end
145145

146146
test "call/2 when persistent session cache doesn't have credentials with custom cookie options", %{conn: conn, config: config} do
147-
config = Keyword.merge(config, persistent_session_cookie_opts: @custom_cookie_opts, persistent_session_cookie_expiration_drift: 20)
147+
config = Keyword.merge(config, persistent_session_cookie_opts: @custom_cookie_opts, persistent_session_cookie_expiration_timeout: 20)
148148
conn =
149149
conn
150150
|> persistent_cookie("persistent_session_cookie", "test")

0 commit comments

Comments
 (0)