Skip to content

Conversation

thebrianchen
Copy link
Contributor

@thebrianchen thebrianchen commented Sep 24, 2025

Adding tracking for expiration in auth sessions with a default of 15mins. Updated example web app to show expiration time.

note that we still need to add functionality for letting user provide the expiration time, not included in this PR.

Pull Request Checklist


PR-Codex overview

This PR focuses on enhancing session management and authentication in the alchemyAuth connector, including session persistence, expiration handling, and improved session state management.

Detailed summary

  • Added DEFAULT_SESSION_EXPIRATION_MS constant for default expiration time.
  • Implemented session duration handling in AuthClient and AuthSession.
  • Enhanced alchemyAuth to persist and restore session state across page reloads.
  • Updated tests to verify session restoration and expiration behavior.
  • Improved session status display in the UI.

The following files were skipped due to too many changes: .cursor/rules/system-prompt.mdc, v4_v5.md

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@thebrianchen thebrianchen changed the title Bc/alchemy auth sessions feat(alchemyAuth): add expiration time ms tracking Sep 24, 2025
@github-actions github-actions bot temporarily deployed to docs-preview September 24, 2025 22:05 Inactive
@thebrianchen thebrianchen changed the title feat(alchemyAuth): add expiration time ms tracking feat: add expiration time ms tracking Sep 24, 2025
Copy link
Contributor

@dphilipson dphilipson left a comment

Choose a reason for hiding this comment

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

This is great! Left a suggestion about naming.

I think we can do a little more in relation to expiration time, which can possibly go in a separate PR. We should also set a timer in the auth client which triggers when the session expires, disconnects the client, and emits a "disconnected" event.

I was thinking of something like the interface in the design doc, particularly the elements disconnect(), on("disconnect", handler), and isDisconnected. As mentioned, it might make sense to do all this together in a separate PR.

/** Credential ID for passkey authentication */
credentialId?: string;
/** Expiration timestamp - if not provided, defaults to 15 minutes from now */
expirationDateMs?: number;
Copy link
Contributor

@dphilipson dphilipson Sep 25, 2025

Choose a reason for hiding this comment

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

The comment and variable name are a bit imprecise: they make it sound like you're providing the timestamp at which the session expires, rather than the length of the session. I'd consider naming the variable either just expirationMs or maybe something like sessionDurationMs, and adjusting the comment.

(I realize the variable name already existed in the code, but I didn't notice it before and now it's becoming part of the public API so needs more attention.)

Edit: Oh whoops, I realize that what I'm describing is in fact what the variable actually does, so the naming and comment are correct. In that case, I'll say that I think it would be more intuitive to have this take the duration instead, since that's what devs are thinking in terms of in 99% of situations.

Copy link
Collaborator

@linnall linnall Sep 25, 2025

Choose a reason for hiding this comment

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

I agree with dphil here. My mental model was that the parameter passed into the AuthSession constructor would be called something like sessionLengthMs and it would be used to set the private element on AuthSession called expirationDateMs

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to sessionDurationMs

bundle,
orgId,
idToken,
authType: type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

as mentioned on authSession.ts, can we rename this to something like sessionLengthMs? assuming that the user will be passing in their desired session length and we are responsible for then calculating the expiration date from it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added logic to recalculate session length based on the expiration date that's deserialized

Base automatically changed from bc/persistence to moldy/v5-base September 25, 2025 23:01
@github-actions github-actions bot temporarily deployed to docs-preview September 25, 2025 23:31 Inactive
@thebrianchen thebrianchen changed the title feat: add expiration time ms tracking feat: add expiration time ms tracking Sep 25, 2025
@thebrianchen thebrianchen merged commit 6e27cf6 into moldy/v5-base Sep 26, 2025
17 of 22 checks passed
@thebrianchen thebrianchen deleted the bc/alchemyAuth-sessions branch September 26, 2025 00:08
thebrianchen added a commit that referenced this pull request Sep 26, 2025
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.

4 participants