-
Notifications
You must be signed in to change notification settings - Fork 13.6k
regression: login hangs on loading when "Forget User Session on Window Close" is enabled #40676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cardoso
wants to merge
10
commits into
release-8.5.0
Choose a base branch
from
fix/CORE-2236
base: release-8.5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6fa8d6c
test: unskip Accounts_ForgetUserSessionOnWindowClose group
cardoso 055e2c5
fix: use session storage when Accounts_ForgetUserSessionOnWindowClose…
cardoso 2b1961e
fix: return early if backend is the same
cardoso 65b259f
fix(account): guard login key migration against storage failures
cardoso 4b809fc
fix: avoid silent return if storage backend is unavailable
cardoso c0326c6
fix: E2EE save password flow reads the wrong storage backend
cardoso c268d4f
review
ggazzo 82c6818
fix: export createMeteorBackedStorage for ddpSdk import
ggazzo ba0cf80
fix: guard storage hook attach and Accounts.config runtime call
ggazzo 7bf9cef
fix: keep storage backend local by default at startup
ggazzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,83 @@ export const STORAGE_KEYS = { | |
|
|
||
| export type StorageKey = (typeof STORAGE_KEYS)[keyof typeof STORAGE_KEYS]; | ||
|
|
||
| const getStorage = (): Storage | undefined => (typeof window !== 'undefined' ? window.localStorage : undefined); | ||
| type StorageBackend = 'local' | 'session'; | ||
|
|
||
| export const getStoredItem = (key: string): string | null => getStorage()?.getItem(key) ?? null; | ||
| const getStorageForBackend = (backend: StorageBackend): Storage | undefined => { | ||
| if (typeof window === 'undefined') { | ||
| return undefined; | ||
| } | ||
|
|
||
| export const setStoredItem = (key: string, value: string): void => getStorage()?.setItem(key, value); | ||
| try { | ||
| return backend === 'session' ? window.sessionStorage : window.localStorage; | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| }; | ||
|
|
||
| export const removeStoredItem = (key: string): void => getStorage()?.removeItem(key); | ||
| const getStorage = (): Storage | undefined => { | ||
| return getStorageForBackend(storageBackend); | ||
| }; | ||
|
|
||
| export const getStoredItem = (key: StorageKey): string | null => getStorage()?.getItem(key) ?? null; | ||
|
|
||
| export const setStoredItem = (key: StorageKey, value: string): void => getStorage()?.setItem(key, value); | ||
|
|
||
| export const removeStoredItem = (key: StorageKey): void => getStorage()?.removeItem(key); | ||
|
|
||
| let storageBackend: StorageBackend = 'local'; | ||
|
|
||
| export const setStorageBackend = (backend: StorageBackend): boolean => { | ||
| if (backend === storageBackend) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!moveLoginKeys(backend)) { | ||
| return false; | ||
| } | ||
|
|
||
| storageBackend = backend; | ||
| return true; | ||
| }; | ||
|
Comment on lines
+43
to
+54
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is all this is to fix the regression or some improvement you've seen? I think it should go to 8.6.0. |
||
|
|
||
| const moveLoginKeys = (backend: StorageBackend): boolean => { | ||
| const keys = [ | ||
| STORAGE_KEYS.USER_ID, | ||
| STORAGE_KEYS.LOGIN_TOKEN, | ||
| STORAGE_KEYS.LOGIN_TOKEN_EXPIRES, | ||
| STORAGE_KEYS.E2EE_PUBLIC_KEY, | ||
| STORAGE_KEYS.E2EE_PRIVATE_KEY, | ||
| STORAGE_KEYS.E2EE_RANDOM_PASSWORD, | ||
| ]; | ||
|
|
||
| const sourceStorage = getStorageForBackend(backend === 'session' ? 'local' : 'session'); | ||
| const targetStorage = getStorageForBackend(backend); | ||
|
|
||
| if (!sourceStorage || !targetStorage) { | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| console.warn('Unable to switch storage backend because source or target storage is unavailable'); | ||
| return false; | ||
| } | ||
|
|
||
| for (const key of keys) { | ||
| let value: string | null; | ||
| try { | ||
| value = sourceStorage.getItem(key); | ||
| } catch { | ||
| continue; | ||
| } | ||
|
|
||
| if (value === null) { | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| targetStorage.setItem(key, value); | ||
| sourceStorage.removeItem(key); | ||
| } catch { | ||
| continue; | ||
| } | ||
| } | ||
| sourceStorage.clear(); | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
|
|
||
| return true; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's what I was expecting from this fix.