vugu / vugu

Vugu: A modern UI library for Go+WebAssembly (experimental)
https://www.vugu.org
MIT License
4.8k stars 175 forks source link

Cookies or Equivalent User Information Storage #141

Closed rigelrozanski closed 7 months ago

rigelrozanski commented 4 years ago

Question Is is possible to create a cookie with Vugu? How may this be accomplished if it is possible.

Is your question related to a problem? Please describe. The basic problem is I want to have the capability to store a user authentication information locally so that login would not be required each time the user access the webpage. So a cookie is not necessarily required per-se however access to some piece of local storage would be required, and as I understand it WASM is sandboxed and does not have local file access.

Suggested Changes I would, if possible like to avoid any contact with JS, and AFAICT there is no current way to accomplish this from the vugu file, so it sounds like this may require vugu changes if it is to be made possible without JS on the developers end.

bradleypeabody commented 4 years ago

As it stands right now, this is a bit outside the scope of what Vugu is intended to do. There are many things that you can only accomplish in Wasm by calling JS, and Vugu is not intended to be a wrapper for all of this functionality.

Using syscall/js you can access the JS environment and for example use document.cookie to get and set cookies. Although I'm sure a wrapper could be made for this, it would be a lot of effort to try to wrap all of the possible browser features, which are currently available, albeit a bit clumsy, via syscall/js.

rigelrozanski commented 4 years ago

Cool, I'm just starting to get my feet wet in vugu / general web-dev UI so this is news to me! I'll attempt to figure this out using syscall/js. It doesn't appear that there are any standalone examples using vugu/js - are there any tutorials or material you'd recommend on using syscall/js generally? I'll probably write out a little gist using vugu+cookies and reference it in this issue once I've got a working example

bradleypeabody commented 4 years ago

Sounds good.

This article has a bit of example code that might be helpful: https://www.aaron-powell.com/posts/2019-02-06-golang-wasm-3-interacting-with-js-from-go/