Skip to content

fix: Add SSR guards to tokenStorage setters and clear method#6

Merged
gin-melodic merged 2 commits intofeature/fature-pbfrom
copilot/sub-pr-5
Feb 13, 2026
Merged

fix: Add SSR guards to tokenStorage setters and clear method#6
gin-melodic merged 2 commits intofeature/fature-pbfrom
copilot/sub-pr-5

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

The tokenStorage object had inconsistent SSR safety—getters checked typeof window !== 'undefined' but setters and clear() called localStorage unconditionally, causing errors in server-side contexts.

Changes

Added window guards to all mutation methods:

  • setToken(), setRefreshToken(), setSessionKey() now no-op when window is undefined
  • clear() now no-ops when window is undefined
// Before
setToken: (token) => localStorage.setItem(TOKEN_KEY, token),

// After
setToken: (token) => {
  if (typeof window !== 'undefined') {
    localStorage.setItem(TOKEN_KEY, token);
  }
},

All tokenStorage methods now handle SSR contexts safely.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor frontend updates based on review feedback fix: Add SSR guards to tokenStorage setters and clear method Feb 13, 2026
Copilot AI requested a review from gin-melodic February 13, 2026 09:39
@gin-melodic gin-melodic marked this pull request as ready for review February 13, 2026 11:54
@gin-melodic gin-melodic merged commit 9364510 into feature/fature-pb Feb 13, 2026
1 check passed
@gin-melodic gin-melodic deleted the copilot/sub-pr-5 branch February 13, 2026 11:55
gin-melodic added a commit that referenced this pull request Feb 14, 2026
* feat: add protobuf support and update auth flow

- Add @bufbuild/protobuf, protobufjs, decimal.js, long, and ts-proto
  dependencies for protobuf functionality
- Add @types/decimal.js as dev dependency
- Introduce 'proto' script in package.json for proto generation
- Replace direct API calls with useRegister hook in register page
- Update useLogin hook usage in login page component
- Modify login mutation parameters to use correct field names
- Update mock user login to use UserLevelType enum values
- Remove manual loading state in favor of mutation pending state
- Adjust routing after registration to dashboard

* feat(accounts): use translationKey for account type labels

- Replace hardcoded label.toLowerCase() with translationKey property
- Update ACCOUNT_TYPES definition to include translationKey field
- Modify Accounts.tsx, AddAccountModal.tsx, and EditAccountModal.tsx
  to use translationKey instead of label for i18n consistency

fix(auth): enhance session key validation and token refresh logic

- Add session key validation in GlobalContext to ensure ALE-encrypted
  endpoints have required session key
- Implement fallback mechanism for token refresh when another tab
  completes the refresh process
- Update getProfile call to use secureAuthService with proper user
  mapping from protobuf response

refactor(2fa): improve 2FA QR code handling

- Update UserProfile component to safely access data.secret properties
- Use optional chaining and default values for QR URL and secret

refactor(network): optimize imports in GlobalContext

- Remove unused apiRequest and API_BASE_PATH imports
- Import secureAuthService for encrypted API calls

* feat(settings): add confirmation flow for base currency updates

- Implement two-step confirmation process for changing base currency
- Add visual feedback during currency selection with confirmation states
- Integrate secureAuthService to update user profile with new main currency
- Add loading states and proper error handling for currency updates
- Include auto-cancel functionality for confirmation after 3 seconds

fix(accounts): replace hardcoded strings with internationalized messages

- Add translation keys for account creation, update, and deletion messages
- Support multiple languages (en, ja, zh-CN, zh-TW) for account operations
- Update success and error toast notifications to use translated content
- Remove hardcoded Chinese strings in favor of i18n implementation

refactor(proto): update UserInput interface with mainCurrency field

- Add optional mainCurrency property to UserInput interface
- Update protobuf serialization/deserialization logic to handle mainCurrency
- Modify default values and message processing for the new field
- Ensure backward compatibility with existing user profiles

refactor(auth): add updateProfile method to secureAuthService

- Export UserInput type for consistent typing across services
- Implement updateProfile endpoint using secureRequest pattern
- Add proper request/response type definitions for profile updates
- Maintain existing authentication flow while adding update capability

chore(accounts): improve mutation hooks with proper translations

- Add i18n support to account CRUD operation hooks
- Update toast notifications to use localized messages
- Fix type annotation for protoInput in update mutation
- Maintain consistent error handling patterns across mutations

refactor(websocket): change error logging level from error to warning

- Update WebSocket error logging to use console.warn instead of console.error
- Maintain same debugging information while reducing log severity
- Keep connection status tracking consistent with new warning approach

* feat(auth): integrate global context for user registration flow

- Import and utilize GlobalContext in the registration page to manage user state
- Update global context with user data upon successful registration
- Ensure seamless transition from registration to dashboard with proper authentication state

fix(accounts): disable balance input for equity accounts

- Extend the condition to disable balance input field for ACCOUNT_TYPE_EQUITY
- Prevent users from modifying balance values for expense, income, and equity account types

chore(deps): update package-lock.json peer dependency declarations

- Add peer property to multiple dependencies in package-lock.json
- Ensure proper peer dependency tracking for react, eslint, typescript and other packages
- Maintain consistency in dependency management across the project

* feat: enhance user feedback and error handling in registration and login flows

* fix: lint problems.

* Update src/context/GlobalContext.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* feat(tests): update TestComponent to reflect user login state

* Update src/components/layout/Sidebar.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/components/features/settings/CurrencySettings.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/components/features/Transactions.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: Add SSR guards to tokenStorage setters and clear method (#6)

* Initial plan

* fix: add window guard to tokenStorage setters and clear method

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* Fix nanos overflow in MoneyHelper.toProto() (#7)

* Initial plan

* fix: normalize nanos overflow in MoneyHelper.toProto()

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use while loop for more robust nanos normalization

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: simplify nanos normalization logic

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use Decimal comparison methods for cleaner code

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use exact equality checks for nanos normalization

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: optimize nanos normalization and clean up tests

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use defensive >= and <= checks for nanos normalization

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* test: add assertions to verify nanos always within valid range

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* fix: fix import sentence to avoid unnecessary runtime imports and potential circular deps.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants