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

fix: Parse Server option extendSessionOnUse not working for session lengths < 24 hours #9113

Open
wants to merge 4 commits into
base: alpha
Choose a base branch
from

Conversation

vivekjoshi556
Copy link
Contributor

Pull Request

This PR helps with dynamically extending session based on session Length.

Issue

Closes: #8981

Approach

I followed a similar approach to what @mman suggested here.

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)

Copy link

Thanks for opening this pull request!

@vivekjoshi556
Copy link
Contributor Author

Hello @mman,
You mentioned that you would beta test. Please look at the solution and let me know what you think.

Copy link

codecov bot commented May 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.79%. Comparing base (f1469c6) to head (da99d51).
Report is 13 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #9113      +/-   ##
==========================================
- Coverage   94.13%   93.79%   -0.35%     
==========================================
  Files         186      186              
  Lines       14687    14731      +44     
==========================================
- Hits        13826    13817       -9     
- Misses        861      914      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mman
Copy link
Contributor

mman commented May 1, 2024

Thanks a lot @vivekjoshi556, I will take a look first thing next week, now OOO.

@vivekjoshi556
Copy link
Contributor Author

Hey @mman. Just wanted to check if you got some time to look at the PR.

@mman
Copy link
Contributor

mman commented May 6, 2024

@vivekjoshi556 The code looks nice and clean, the tests as well. Will try to deploy to my stage env later today.

@vivekjoshi556
Copy link
Contributor Author

Hey @mman Just wanted to check in again.

@mtrezza if you have inputs as well, please let me know.

There is a minor issue with linting I'll fix it in the next push, anything else let me know.

src/Auth.js Outdated Show resolved Hide resolved
spec/Auth.spec.js Outdated Show resolved Hide resolved
Signed-off-by: Manuel <[email protected]>
src/Auth.js Show resolved Hide resolved
@mtrezza
Copy link
Member

mtrezza commented May 10, 2024

This fix just shifts the problem downwards from 24 hours to 1 minute. Because for a session length of <1 minute, the problem in #8981 persists.

I wonder whether we need such a complex logic for this. If I understand #8981 (comment) correctly, the purpose of this logic is to find a middle ground between:

  • extending the session on every request --> con: high DB writes
  • ensuring that the session extends before it expires --> con: session would never get extended

Wouldn't it be simpler to extend the session when the remaining session token validity time reached < 50% of the session length?

For example:

  • session length 1 year --> session extends if remaining time is < 182 days
  • session length 1 day --> session extends if remaining time is < 12 hours
  • session length 1 hour --> session extends if remaining time is < 30 mins
  • session length 1 minute --> session extends if remaining time is < 30 secs

Pros:

  • Simple to document and understand
  • This adapts dynamically to the session length, instead of some arbitrary extension trigger times
  • It's easy to make this configurable via a new Parse Server option in the future, by letting a developer configure the threshold, e.g. 50% as in examples above.

And could you please document this new behavior in the Parse Server option extendSessionOnUse?

Comment on lines +304 to +315
tests.forEach(({ title, sessionLength, sessionUpdatedAt, result }) => {
it(`shouldUpdateSessionExpiry() when ${title}`, async () => {
const { shouldUpdateSessionExpiry } = require('../lib/Auth');
const update = new Date();
update.setTime(update.getTime() - sessionUpdatedAt * 1000);
const res = shouldUpdateSessionExpiry(
{ sessionLength: sessionLength },
{ updatedAt: update }
);

expect(res).toBe(result);
});
Copy link
Member

@mtrezza mtrezza May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor by moving the loop into the test. We don't need a separate test log for every param. Considering #9113 (comment), 1 simple test would be enough, not sure whether you need a loop at all here.

@mtrezza mtrezza changed the title fix: ExtendSessionOnUse Updates fix: Parse Server option extendSessionOnUse not working for session lengths < 24 hours May 10, 2024
@mtrezza
Copy link
Member

mtrezza commented May 14, 2024

@vivekjoshi556 Just a friendly ping here; if you could simplify the logic and add the functionality description to the option docs (this repo, not the docs repo), then we could go ahead and merge.

@vivekjoshi556
Copy link
Contributor Author

So sorry just got a bit swamped with work. Give me some time

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

Successfully merging this pull request may close these issues.

extendSessionOnUse not working as expected
3 participants