Skip to content

Commit 9cb23db

Browse files
committed
docs: Clarify logout example to show discarding the shape
The previous example incorrectly suggested shape.stop() would clear data. Updated to show the full login/logout flow where the shape is discarded entirely and recreated on next login. https://claude.ai/code/session_013RcPWarM8BFHnGvc4hMrVj
1 parent e2f8b1f commit 9cb23db

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

website/docs/guides/auth.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,25 +465,33 @@ This ensures proper isolation of cached shape data based on authentication conte
465465

466466
### Clearing Client-Side Data on Logout
467467

468-
The `Vary` header handles HTTP cache isolation, but your client application may also hold synced data in memory or local storage. When a user logs out, you should perform a full refetch to clear this data and ensure the new session starts fresh.
468+
The `Vary` header handles HTTP cache isolation, but your client application also holds synced shape data in memory. When a user logs out, you need to discard the old shape and create a fresh one on the next login to ensure the previous user's data is cleared.
469469

470470
```typescript
471-
async function handleLogout() {
472-
// Clear auth credentials
473-
await clearAuthToken()
471+
let shape: Shape | null = null
474472

475-
// Restart the shape stream to clear synced data
476-
// This ensures the old user's data is removed from memory
477-
shape.stop()
473+
async function handleLogin(user: User) {
474+
// Create a new shape for the authenticated user
475+
shape = new Shape({
476+
url: `/api/shapes/items`,
477+
headers: {
478+
Authorization: `Bearer ${user.token}`,
479+
},
480+
})
481+
}
482+
483+
async function handleLogout() {
484+
// Discard the shape entirely - this clears the synced data from memory
485+
shape = null
478486

479-
// Optionally, if you're using persistence, clear the stored data
487+
// If using persistence, also clear the stored data
480488
// localStorage.removeItem('my-shape-data')
481489

482-
// Start fresh on next login - the shape will refetch from scratch
490+
await clearAuthToken()
483491
}
484492
```
485493

486-
Without this step, stale data from the previous user's session could remain in your application state even after logout, potentially being displayed to a different user or persisted locally.
494+
Without discarding the shape on logout, the previous user's data remains in memory and could be displayed to a different user.
487495

488496
## Notes
489497

0 commit comments

Comments
 (0)