Abstract cookies invalidation.

main
absc 2024-08-15 21:12:07 +00:00
parent a18fa4989c
commit c9fcd47064
2 changed files with 17 additions and 8 deletions

View File

@ -25,7 +25,7 @@ from the dudeswave database.
-include_lib("storage/include/storage.hrl"). -include_lib("storage/include/storage.hrl").
-export([authenticate/2, details/1, new/3, -export([authenticate/2, details/1, new/3,
update/4, delete/1, logout/2, auth_cookies/1]). update/4, delete/1, logout/2, auth_cookies/1, invalidate_cookies/1]).
-doc """ -doc """
Verify a session with an existing cookie. Verify a session with an existing cookie.
@ -265,3 +265,15 @@ auth_cookies(Req) ->
dudename], Req), dudename], Req),
{User, Cookie}. {User, Cookie}.
-spec invalidate_cookies(Req) -> Req0 when
Req :: cowboy_req:req(),
Req0 :: cowboy_req:req().
invalidate_cookies(Req) ->
Req0 = cowboy_req:set_resp_cookie(<<"dudeauth">>, <<"">>, Req,
#{max_age => 0}),
Req1 = cowboy_req:set_resp_cookie(<<"dudename">>, <<"">>, Req0,
#{max_age => 0}),
Req1.

View File

@ -139,12 +139,9 @@ delete_resource(Req, State) ->
case dudeswave_auth:logout(User, Auth) of case dudeswave_auth:logout(User, Auth) of
ok -> ok ->
Req0 = cowboy_req:set_resp_cookie(<<"dudeauth">>, Auth, Req, {true, dudeswave_auth:invalidate_cookies(Req), State};
#{max_age => 0}), {error, _} ->
Req1 = cowboy_req:set_resp_cookie(<<"dudename">>, User, Req0, {false, Req, State}
#{max_age => 0}),
{true, Req1, State};
{error, _} -> {false, Req, State}
end. end.
delete_completed(Req, State) -> {false, Req, State}. delete_completed(Req, State) -> {false, Req, State}.