You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: website/docs/guides/auth.md
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -465,25 +465,33 @@ This ensures proper isolation of cached shape data based on authentication conte
465
465
466
466
### Clearing Client-Side Data on Logout
467
467
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.
469
469
470
470
```typescript
471
-
asyncfunction handleLogout() {
472
-
// Clear auth credentials
473
-
awaitclearAuthToken()
471
+
let shape:Shape|null=null
474
472
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
+
asyncfunction handleLogin(user:User) {
474
+
// Create a new shape for the authenticated user
475
+
shape=newShape({
476
+
url: `/api/shapes/items`,
477
+
headers: {
478
+
Authorization: `Bearer ${user.token}`,
479
+
},
480
+
})
481
+
}
482
+
483
+
asyncfunction handleLogout() {
484
+
// Discard the shape entirely - this clears the synced data from memory
485
+
shape=null
478
486
479
-
//Optionally, if you're using persistence, clear the stored data
487
+
//If using persistence, also clear the stored data
480
488
// localStorage.removeItem('my-shape-data')
481
489
482
-
// Start fresh on next login - the shape will refetch from scratch
490
+
awaitclearAuthToken()
483
491
}
484
492
```
485
493
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.
0 commit comments