@@ -40,10 +40,6 @@ defmodule PowPersistentSession.Plug.Cookie do
4040 `[max_age: max_age, path: "/"]` where `:max_age` is the value defined in
4141 `:persistent_session_ttl`.
4242
43- * `:persistent_session_cookie_expiration_timeout` - integer value in
44- seconds for how much time should go by before cookie should expire after
45- the token is fetched in `authenticate/2`. Defaults to 10.
46-
4743 ## Custom metadata
4844
4945 You can assign a private `:pow_persistent_session_metadata` key in the conn
@@ -74,10 +70,9 @@ defmodule PowPersistentSession.Plug.Cookie do
7470 alias Pow . { Config , Operations , Plug , UUID }
7571
7672 @ cookie_key "persistent_session"
77- @ cookie_expiration_timeout 10
7873
7974 @ doc """
80- Sets a persistent session cookie with an auto generated token.
75+ Sets a persistent session cookie with a randomly generated unique token.
8176
8277 The token is set as a key in the persistent session cache with the id fetched
8378 from the struct. Any existing persistent session will be deleted first with
@@ -89,8 +84,8 @@ defmodule PowPersistentSession.Plug.Cookie do
8984 value will look like:
9085 `{[id: user_id], session_metadata: [fingerprint: fingerprint]}`
9186
92- The unique cookie id will be prepended by the `:otp_app` configuration
93- value, if present.
87+ The unique token will be prepended by the `:otp_app` configuration value, if
88+ present.
9489 """
9590 @ spec create ( Conn . t ( ) , map ( ) , Config . t ( ) ) :: Conn . t ( )
9691 def create ( conn , user , config ) do
@@ -138,10 +133,11 @@ defmodule PowPersistentSession.Plug.Cookie do
138133 end
139134
140135 @ doc """
141- Expires the persistent session cookie .
136+ Expires the persistent session.
142137
143- If a persistent session cookie exists it'll be updated to expire immediately,
144- and the token in the persistent session cache will be deleted.
138+ If a persistent session cookie exists the token in the persistent session
139+ cache will be deleted, and cookie deleted with
140+ `Plug.Conn.delete_resp_cookie/3.
145141 """
146142 @ spec delete ( Conn . t ( ) , Config . t ( ) ) :: Conn . t ( )
147143 def delete ( conn , config ) do
@@ -165,12 +161,7 @@ defmodule PowPersistentSession.Plug.Cookie do
165161 end
166162
167163 defp delete_cookie ( conn , cookie_key , config ) do
168- opts =
169- config
170- |> cookie_opts ( )
171- |> Keyword . put ( :max_age , - 1 )
172-
173- Conn . put_resp_cookie ( conn , cookie_key , "" , opts )
164+ Conn . delete_resp_cookie ( conn , cookie_key , cookie_opts ( config ) )
174165 end
175166
176167 @ doc """
@@ -179,22 +170,13 @@ defmodule PowPersistentSession.Plug.Cookie do
179170 If a persistent session cookie exists, it'll fetch the credentials from the
180171 persistent session cache.
181172
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-
188173 If credentials was fetched successfully, the token in the cache is deleted, a
189174 new session is created, and `create/2` is called to create a new persistent
190- session cookie. This will override any expiring cookie.
175+ session cookie.
191176
192177 If a `:session_metadata` keyword list is fetched from the persistent session
193178 metadata, all the values will be merged into the private
194179 `:pow_session_metadata` key in the conn.
195-
196- The expiration date for the cookie will be reset on each request where a user
197- is assigned to the conn.
198180 """
199181 @ spec authenticate ( Conn . t ( ) , Config . t ( ) ) :: Conn . t ( )
200182 def authenticate ( conn , config ) do
@@ -210,16 +192,15 @@ defmodule PowPersistentSession.Plug.Cookie do
210192
211193 case conn . req_cookies [ cookie_key ] do
212194 nil -> conn
213- key_id -> do_authenticate ( conn , cookie_key , key_id , config )
195+ key_id -> do_authenticate ( conn , key_id , config )
214196 end
215197 end
216198 defp maybe_authenticate ( conn , _user , _config ) , do: conn
217199
218- defp do_authenticate ( conn , cookie_key , key_id , config ) do
200+ defp do_authenticate ( conn , key_id , config ) do
219201 { store , store_config } = store ( config )
220202 res = store . get ( store_config , key_id )
221203 plug = Plug . get_plug ( config )
222- conn = expire_cookie ( conn , cookie_key , key_id , config )
223204
224205 case res do
225206 :not_found ->
@@ -232,17 +213,6 @@ defmodule PowPersistentSession.Plug.Cookie do
232213 end
233214 end
234215
235- defp expire_cookie ( conn , cookie_key , key_id , config ) do
236- max_age = Config . get ( config , :persistent_session_cookie_expiration_timeout , @ cookie_expiration_timeout )
237- opts =
238- config
239- |> cookie_opts ( )
240- |> Keyword . put ( :max_age , max_age )
241-
242- Conn . put_resp_cookie ( conn , cookie_key , key_id , opts )
243- end
244-
245-
246216 defp fetch_and_auth_user ( conn , { clauses , metadata } , plug , config ) do
247217 clauses
248218 |> filter_invalid! ( )
0 commit comments