Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage documentation #6

Open
PVince81 opened this issue Oct 16, 2020 · 13 comments
Open

Usage documentation #6

PVince81 opened this issue Oct 16, 2020 · 13 comments

Comments

@PVince81
Copy link

I tried to infer usage from the source code but it isn't as straightforward.

Would be good to add some usage examples in the README for volatile and persistent, and maybe best practices.

@ChristophWurst
Copy link
Contributor

Yep, sorry. There is also no online docs right now. I ran out of time with this one, but you should find some infos at #1.

@PVince81
Copy link
Author

PVince81 commented Oct 16, 2020

Quick notes:

import { getBuilder } from '@nextcloud/browser-storage'

// browser storage, clears after the browser is closed (uses sessionStorage internally)
browserStorage = getBuilder('appname').build()

// survives page changes and stays after log out (uses localStorage internally)
persistentStorage = getBuilder('appname').persist().build()

// survives page changes but clears after logging out (uses localStorage internally)
userSessionStorage = getBuilder('appname').clearOnLogout().build()

// same as `clearOnLogout()` alone ??
userSessionStorage2 = getBuilder('appname').persist().clearOnLogout().build()

@ChristophWurst can you clarify if I got it right ?

we could also use the proposed naming in the code

@PVince81
Copy link
Author

  • mention how one needs to explicitly call clear() whenever a user logs out (this module cannot detect this on its own) for the clearOnLogout() logic to be effective

@ChristophWurst
Copy link
Contributor

* mention how one needs to explicitly call `clear()` whenever a user logs out (this module cannot detect this on its own) for the `clearOnLogout()` logic to be effective

The original idea was to include this package in the server and call the clear there as one central code to do this. It's not intended for the app to deal with this.

@ChristophWurst
Copy link
Contributor

clears after a page refresh (uses sessionStorage internally)

⚠️ https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

A page session lasts as long as the browser is open, and survives over page reloads and restores.

@PVince81
Copy link
Author

ah yes, it's only if you change the URL.
I also noticed in that past that if you "open a new tab" from that tab, it also preserves the storage there

@PVince81
Copy link
Author

adjusted to "// browser storage, clears after the browser is closed (uses sessionStorage internally)"

@PVince81
Copy link
Author

PVince81 commented Oct 21, 2020

I just discovered that all of localStorage gets cleared on logout (given that "clear=1" is passed and it is when using the top right menu): https://github.com/nextcloud/server/blob/master/core/src/login.js#L34

so even when using "persist()"

@MorrisJobke
Copy link

I just discovered that all of localStorage gets cleared on logout (given that "clear=1" is passed and it is when using the top right menu): https://github.com/nextcloud/server/blob/master/core/src/login.js#L34

Was on purpose, because CardDav/Caldav stuff was cached in there and thus needs to be cleaned as it would otherwise leak personal data. At least that is what I remember ... Was done by @georgehrke

@nickvergessen
Copy link
Contributor

So let's switch that to session storage if the data should not survive?!

@ChristophWurst
Copy link
Contributor

So let's switch that to session storage if the data should not survive?!

⚠️ there is no semantics of logout for sessions storage. as long as you don't close the browser the session storage remains. so if you log into nc on someone else's computer, then log out, they will still have access to the sensitive data.

@nickvergessen
Copy link
Contributor

Well sure, but at least browser storage is even more wrong for sensitive data

@ChristophWurst
Copy link
Contributor

Of course

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants