Add Session Refresh Callbacks #23
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds callbacks for session refresh success and failure in the AuthKit React Router SDK, providing a more flexible and developer-friendly approach to handling session refreshes.
Note: This is a port of workos/authkit-remix#58 to the React Router library.
Problem
Previously, when a session refresh failed, the SDK would simply delete the cookie and redirect the user to the root path (/). This hard-coded behavior provided no visibility into why the refresh failed and no way for developers to customize the error handling flow.
Solution
This PR introduces:
onSessionRefreshSuccesscallback - Called when a session is successfully refreshedonSessionRefreshErrorcallback - Called when a session refresh failsThese callbacks allow developers to implement custom error handling, logging, analytics, and user messaging around session lifecycle events.
Implementation Details
SessionRefreshErrorclass to properly identify refresh failuresExample Usage
Backward Compatibility
To maintain backward compatibility, the default behavior (redirect to
/and delete cookie) is preserved when no onSessionRefreshError callback is provided.