@@ -3,8 +3,8 @@ defmodule PowPersistentSession.Plug.Cookie do
3
3
This plug will handle persistent user sessions with cookies.
4
4
5
5
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.
8
8
9
9
If an assigned private `:pow_session_metadata` key exists in the conn with a
10
10
keyword list containing a `:fingerprint` key, that fingerprint value will be
@@ -41,9 +41,9 @@ defmodule PowPersistentSession.Plug.Cookie do
41
41
`[max_age: max_age, path: "/"]` where `:max_age` is the value defined in
42
42
`:persistent_session_ttl`.
43
43
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 has a fetched in `authenticate/2`. Defaults to 10.
47
47
48
48
## Custom metadata
49
49
@@ -75,7 +75,7 @@ defmodule PowPersistentSession.Plug.Cookie do
75
75
alias Pow . { Config , Plug , UUID }
76
76
77
77
@ cookie_key "persistent_session_cookie"
78
- @ cookie_expiration_drift 10
78
+ @ cookie_expiration_timeout 10
79
79
80
80
@ doc """
81
81
Sets a persistent session cookie with an auto generated token.
@@ -177,16 +177,24 @@ defmodule PowPersistentSession.Plug.Cookie do
177
177
Authenticates a user with the persistent session cookie.
178
178
179
179
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 invalidated,
189
+ a new session is created, and `create/2` is called to create a new persistent
190
+ session cookie. This will override any expiring cookie.
184
191
185
192
If a `:session_metadata` keyword list is fetched from the persistent session
186
193
metadata, all the values will be merged into the private
187
194
`:pow_session_metadata` key in the conn.
188
195
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.
190
198
"""
191
199
@ spec authenticate ( Conn . t ( ) , Config . t ( ) ) :: Conn . t ( )
192
200
def authenticate ( conn , config ) do
@@ -226,7 +234,7 @@ defmodule PowPersistentSession.Plug.Cookie do
226
234
end
227
235
228
236
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 )
230
238
opts =
231
239
config
232
240
|> cookie_opts ( )
0 commit comments