Use the auth_cookie function to extract cookies.

main
absc 2024-08-15 21:02:41 +00:00
parent dac21c4537
commit a18fa4989c
1 changed files with 3 additions and 5 deletions

View File

@ -94,8 +94,7 @@ forbidden(Req, State) ->
<<"POST">> -> <<"POST">> ->
{false, Req, State}; {false, Req, State};
_ -> _ ->
#{dudeauth := Auth, dudename := User} = cowboy_req:match_cookies([dudeauth, {User, Auth} = dudeswave_auth:auth_cookies(Req),
dudename], Req),
case dudeswave_auth:authenticate(User, {cookie, Auth}) of case dudeswave_auth:authenticate(User, {cookie, Auth}) of
{error, service_unavailable} -> exit(service_unavailable); {error, service_unavailable} -> exit(service_unavailable);
@ -113,7 +112,7 @@ content_types_accepted(Req, State) ->
end. end.
resource_exists(Req, State) -> resource_exists(Req, State) ->
#{dudename := User} = cowboy_req:match_cookies([dudename], Req), {User, _} = dudeswave_auth:auth_cookies(Req),
case dudeswave_auth:details(User) of case dudeswave_auth:details(User) of
[] -> [] ->
@ -136,8 +135,7 @@ is_conflict(Req, State) -> {true, Req, State}.
allow_missing_post(Req, State) -> {false, Req, State}. allow_missing_post(Req, State) -> {false, Req, State}.
delete_resource(Req, State) -> delete_resource(Req, State) ->
#{dudename := User, dudeauth := Auth} = cowboy_req:match_cookies([dudename, {User, Auth} = dudeswave_auth:auth_cookies(Req),
dudeauth], Req),
case dudeswave_auth:logout(User, Auth) of case dudeswave_auth:logout(User, Auth) of
ok -> ok ->