-
-
Notifications
You must be signed in to change notification settings - Fork 248
feat(supabase_flutter): use SharedPreferences for access token #608
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
Conversation
SharedPreferences uses a prefix, so it's not possible to use the package to use the js localstorage entry as well. I've now accessed the |
Can we do this and use the same storage key as the JS SDK? |
No, because that's not per instance, but for the global Shared preference and would therefore conflict with the other users use of this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we still match the key excluding the prefix so that developers that want to use Flutter web in combination with the JS client library can just add SharedPreferences. setPrefix('')
to their code baase?
I wouldn't do that, because you would need to use an
|
It seems like there are discussions around exposing the underlying storage for shared preferences. If this lands, we might be able to access the session object stored by supabase-js from this library. It's not going to make it compatible with supabase-js just yet because of the |
Ah supabase-js uses a different storage key, okay. Will fix that. I don't get your first point, though. I've already implemented the access to the So do we want both to work together or not? |
I didn't realize that for web, you are access the local storage directly, instead of accessing it though shared preferences. That's great! I didn't have to worry about all the prefix issues and stuff that I had mentioned previously 😂 You might be aware of it, but the JS SDK doesn't stringify the session object when storing it in the local storage, so that is something we have to take into account when storing and retrieving session on the web with local storage.
Yeah, didn't think about this one, but good catch! Let's do it!
Yes, I think it would be great to have compatibility between the JS SDK and supabase_flutter! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Just one final check, and I think this PR is good to be merged!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! Making supabase_flutter compatible with the JS client is huge 💪
Just my two cents. Have you guys considered using: https://pub.dev/packages/flutter_secure_storage instead of SharedPreferences? |
It's not really necessary, as the access token is accessible on the web via localstorage as well. And it's easier to maintain as it's supported on all platforms and means a dependency less. If you want to, you can still use it by providing your own |
I've assumed that SharedPreferences replaces Hive on all platforms. For Web SharedPreferences is more than fine, browsers have built-in security, so no other website can steal the token (on desktop that's not the case). |
To follow up on my previous comment, what I really meant is where the session data ends on the user's device and whether it is actually secure to use SharedPreferences (that is whether other apps could potentially access Supabase session). It's still way better than a previously used Hive. Please find below comparison tables: flutter_secure_storage
shared_preferences
|
Changes
Switches from Hive to Shared Preferences for storing the access token
This is done by still including the Hive package: