<div dir="ltr">Hi all<div><br></div><div style>Imagine an auth protocol over a websocket: client sends credentials, server responds with either success or failure. If success, it should set some persistent state so if the user reloads the page, the session will continue until either logout or some timeout</div>
<div style><br></div><div style>I'm trying to set a cookie from a websocket handler, such that after a page reload, in the websocket handler init i can try to read back the cookie and check for it's validity and if valid, resume the session without the user needing to login again</div>
<div style><br></div><div style>here is some code i tried with no success, i.e upon reload, the cookie is no longer there (or perhaps is never getting set by the handler to begin with)</div><div style><br></div><div style>
<div>websocket_handle({text, Input}, Req, State) -></div><div>  lager:debug("stream received ~s", [Input]),</div><div>  Req2 = cowboy_req:set_resp_cookie(<br></div><div>    <<"auth">>,</div>
<div>    [<<"test">>],</div><div>    [{max_age, 600}, {path, "/"}, {secure, true}, {http_only, true}],</div><div>    Req</div><div>  ),</div><div>  {ok, Req3} = cowboy_req:reply(200, Req2),<br>
</div><div>  {ok, Req3, NewState}.<br></div></div><div style><br></div><div style>... or alternatively:</div><div style><br></div><div style><div>{reply, {text, Output}, Req2, NewState}.</div><div><br></div></div><div style>
as the last line</div><div style><br></div><div style>after the socket terminates and i try to reload page i do this in websocket init:</div><div style><br></div><div style>{Cookie, Req2} = cowboy_req:cookie(<<"auth">>, Req),<br>
</div><div style><div><br></div><div style>and there are no cookies</div><div style><br></div><div style><br></div><div style>any ideas what i'm doing wrong?</div><div style>is this even possible with websocket or do i pretty much have to have a dedicated regular http roundtrip to set the auth cookie?</div>
<div style><br></div><div style>Thanks</div></div><div style><br></div><div style><br></div></div>