Abstract cookies invalidation.
parent
a18fa4989c
commit
c9fcd47064
|
@ -25,7 +25,7 @@ from the dudeswave database.
|
|||
-include_lib("storage/include/storage.hrl").
|
||||
|
||||
-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 """
|
||||
Verify a session with an existing cookie.
|
||||
|
@ -264,4 +264,16 @@ auth_cookies(Req) ->
|
|||
#{dudeauth := Cookie, dudename := User} = cowboy_req:match_cookies([dudeauth,
|
||||
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.
|
|
@ -139,12 +139,9 @@ delete_resource(Req, State) ->
|
|||
|
||||
case dudeswave_auth:logout(User, Auth) of
|
||||
ok ->
|
||||
Req0 = cowboy_req:set_resp_cookie(<<"dudeauth">>, Auth, Req,
|
||||
#{max_age => 0}),
|
||||
Req1 = cowboy_req:set_resp_cookie(<<"dudename">>, User, Req0,
|
||||
#{max_age => 0}),
|
||||
{true, Req1, State};
|
||||
{error, _} -> {false, Req, State}
|
||||
{true, dudeswave_auth:invalidate_cookies(Req), State};
|
||||
{error, _} ->
|
||||
{false, Req, State}
|
||||
end.
|
||||
|
||||
delete_completed(Req, State) -> {false, Req, State}.
|
||||
|
|
Loading…
Reference in New Issue