Convert Sign-Out API to POST and Implement Form-Based Sign-Out #25
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.
Issue Description
The current implementation of the sign-out functionality uses a GET API endpoint and a Next.js Link component. This has led to unexpected behavior where users are being signed out unintentionally, particularly in production environments.
Symptoms
Root Cause Analysis
The root cause of this issue is a combination of factors:
GET API for State-Changing Action: The sign-out API is currently implemented as a GET endpoint. GET requests should be used for retrieving data, not for actions that change server-side state.
Next.js Link Prefetching: Next.js automatically prefetches links in the viewport for performance optimization. This includes API routes.
Unintended API Calls: Due to the combination of points 1 and 2, the sign-out API is being called unintentionally when the sign-out link enters the viewport, even if the user doesn't click it.
Proposed Changes
To address this issue, I propose the following changes:
Why These Changes?
POST for State-Changing Actions:
Form Submission Instead of Link:
Preventing Accidental Sign-Outs: