Comments (10)
Perhaps there's a simpler way to create a new Capacitor plugin that has both userbase-js
and path-package
as dependencies?
I did something similar for the Cordova plugin, which needed to use a custom scrypt
plugin for the password hashing algorithm. The Cordova plugin overrides the password hashing algorithm used by userbase-js
internally by overriding a passwordHashAlgo
param in signUp
, signIn
, and updateUser
:
userbase/src/cordova-plugin-userbase/www/userbase.js
Lines 37 to 53 in a63b34a
Maybe there's an even simpler way to do it in this case.
It might end up being more effort than it's worth if you can just use path-package
in your app though. Perhaps if others express interest in a Capacitor plugin then it's worth exploring the plugin route further. Your call :)
from userbase.
May have answered my own question here: https://capacitorjs.com/docs/guides/storage.
"...your app needs to expect that the data will be lost eventually. This is because the OS will reclaim local storage from Web Views if a device is running low on space."
Although my device isn't low on storage, there could be other reasons the OS would evict the space.
from userbase.
@j-berman Looking for your thoughts here. For Capacitor applications that use Userbase, local storage is not a long-term data storage solution, as the data can get cleared and session lost. I used patch-package to prove replace local storage with this capacitor plugin (UserDefaults on iOS, SharedPreferences on Android, local storage on web). It works on all 3 platforms and successfully maintains user sessions.
The question is this, should I:
- Just use patch-package in my app
- Consider forking userbase to a new repo (i.e.
@capacitor-community/userbase
or something) where the only difference is capacitor support? The new project could like here with the Capacitor Community.
from userbase.
@j-berman wow, for some reason I wasn't aware of the Cordova plugin, or I forgot about it! I may be able to use the Cordova plugin in place of the regular userbase-js package. I'll test it out later today.
I will say that updating to use the new storage method did not work for me. I checked the app this morning and was signed out. So my session lasted maybe 6 days. Maybe the Cordova plugin will be better!
from userbase.
@j-berman would be curious if you're using the Cordova plugin and if you've had session issues? I suppose it could have to do with my implementation, maybe a race condition with init or something, but I really don't think so.
from userbase.
I've just come to realize this is only an issue on iOS. I just picked up an old Android phone for testing, opened the app, and my session from months ago was still active and working as expected.
from userbase.
@j-berman Can you explain why expirationDate
behaves this way?
When I sign in, my userbaseCurrentSession
has a value of:
{
"username": "jneterer",
"signedIn": true,
"sessionId": "...",
"creationDate": "2022-12-09T05:21:46.989Z",
"expirationDate": "2023-12-09T05:21:46.989Z"
}
However when I close/refresh the browser tab or window/app and open it again, my expirationDate
is now only only 24 hours from now (instead of 365 days as set on sign in, see above). Every subsequent close+open adds 24 hours to the expiration date.
{
"username": "jneterer",
"signedIn": true,
"sessionId": "...",
"creationDate": "2022-12-09T05:21:46.989Z",
"expirationDate": "2022-12-10T05:22:24.319Z"
}
Wondering if this has anything to do with it. Maybe not.
from userbase.
Sounds like this might be the issue you're running into!
When a user resumes a session via init
, Userbase will set the session to expire 24 hours from that point in time by default. You would have to set sessionLength
in init
in order to have the session extend your desired length.
This is odd behavior on Userbase's end. If sessionLength
isn't provided in init
, then it should stick with the session the user already has going (the expiration should not change). That seems more reasonable/what you were expecting too.
Separately, have you double checked to see that Capacitor is indeed clearing local storage? It sounds like the above may have been the root cause of the issue here.
from userbase.
Maybe it is! The only thing that makes me think it may not be, is this isn't an issue on Android. I just opened the app up a test device that I hadn't picked up for months and I was still signed in.
Wow, I didn't realize you had to set sessionLength
on init
. I'll have to try that and see if it makes a difference. I agree, if it isn't provided in init
, it should respect what was set on signIn
.
I'm going to have to re-verify. I switched to using the preferences capacitor plugin to test if that would persist the session (uses UserDefaults on iOS and SharedPreferences on Android), but it didn't, which might come back to the init
problem. I'll have to do another test to see but without the storage modification.
from userbase.
@j-berman Results from two tests on iOS:
- Don't set
sessionLength
oninit
. Result - open more than 24 hours after sign in, logged out. - Set
sessionLength
oninit
to 365. Result - open more than 24 hours after sign in, still logged in.
The above is also true on the web. I don't believe this is happening on Android, but it doesn't make sense why not.
I think the solution is two part:
- Set
sessionLength
oninit
(however should probably be updated in a PR to by default respect the value given onsignIn
) - Use an alternative storage location to localStorage for session, like this capacitor plugin (UserDefaults on iOS, SharedPreferences on Android, local storage on web).
from userbase.
Related Issues (20)
- Features Request - Admin API (+ Bounty Reward) HOT 3
- shareDatabase issues
- Feature request: metered trials as opposed to timed trials HOT 3
- forgotPassword with server-side-encryption HOT 1
- Feature Request: 2FA
- How to read a database with admin API? (Question) HOT 4
- How to remove a database? HOT 3
- [userbase-js] passwordHashAlgo is missing in types
- Automatic Tax Collection with Stripe HOT 4
- Close Userbase Node HOT 2
- Prevent registration, or limit app users to 1 HOT 2
- Error "Buffer2 is undefined" when using userbase-js with SvelteKit HOT 3
- Is this project still alive? HOT 1
- All users can view all other items created.
- Feature Request: Verify user during signup to avoid dump email ids.
- Service Unavailable for the last couple of days HOT 3
- Missing Data Stored HOT 2
- Third Party Cookie Issues with Stripe
- ServiceUnavailable: Service unavailable. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from userbase.