简体   繁体   中英

Using Cookies in Yew

I'm building a Rust + Yew app rendered on the client side. After looking for some time in the docs, I couldn't found the proper way to handle cookies. Does anybody knows how to do it?

I want to set an auth token in the cookies.

Have a look at wasm-cookies if you just want to handle cookies on the client side. The library comes with its pitfals but after struggling a bit in the beginning I think it is ok to use.

I personally find that gloo-storage provides a much more intuitive way to handle user information on the client side if that is whay you are aiming for and if you are ok with using local/session storage and not cookie storage (which come all with its drawbacks and benefits).

If you want to use cookies to handle user sessions, authentication, etc. and if you use actix for your backend I found actix-session to be easy to use. They provide a copy-paste example which works out of the box and should give you a quick start with authentication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM