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

even better user cookies #126

Merged
merged 3 commits into from
Jan 20, 2024
Merged

even better user cookies #126

merged 3 commits into from
Jan 20, 2024

Conversation

farisashai
Copy link
Member

@farisashai farisashai commented Jan 19, 2024

Info

Implemented improvement suggested here: https://discordapp.com/channels/573028991527550986/1012204566122598431/1197469917071548436

Since cookies do not store a date created attribute, the idea is that whenever the user cookie is set on the client, it is given a maxAge of 5 minutes, after which it is automatically deleted on the browser. Since the auth token has a lifespan of 2 weeks, it can be used repeatedly to re-generate the user cookie whenever it expires and deletes. (When the auth token expires, we are forced to logout to re-generate a new one).

This solves the problem of requesting an up-to-date version of the user object on every single page that needs it because now they will all rely on the shared cookie and this cookie itself will be updated whenever it is needed and does not exist.

This improvement relies on the assumption that any client side API modifications to the user object will also update it in real-time such as the way the edit profile functions so it is never out of sync with the API on a single device.

The only edge case that will fail is checking into an event or editing a user profile on 2 separate devices in under 5 minutes, which may display a invalid UI for this duration until it get's wiped and updated to the correct data subsequently.

With this change, the user API will be hit once every 5 minutes at most instead of on every page route change.

Changes

  • fix a small bug where eventmodal wasn't using the fixUrl function to pad links correctly
  • implement feature described above

Type of Change

  • Bug Fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • Logistics Change (A change to a README, description, or dev workflow setup like
    linting/formatting)
  • Continuous Integration Change (Related to deployment steps or continuous integration
    workflows)
  • Other: (Fill In)

Testing

I have tested that my changes fully resolve the linked issue ...

  • locally on Desktop.
  • on the live deployment preview on Desktop.
  • on the live deployment preview on Mobile.
  • I have added new Cypress tests that are passing.

Checklist

  • I have performed a self-review of my own code.
  • I have followed the style guidelines of this project.
  • I have documented any new functions in /src/lib/* and commented hard to understand areas
    anywhere else.
  • My changes produce no new warnings.

Screenshots

Copy link

vercel bot commented Jan 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
membership-portal-ui-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2024 2:13pm

Copy link
Contributor

@alexzhang1618 alexzhang1618 left a comment

Choose a reason for hiding this comment

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

Changes generally LGTM, just some questions:

src/lib/api/UserAPI.ts Outdated Show resolved Hide resolved
src/lib/managers/AccountManager.ts Outdated Show resolved Hide resolved
@farisashai farisashai merged commit e8cfc0f into main Jan 20, 2024
5 checks passed
@farisashai farisashai deleted the user-cookie-refresh branch January 20, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants