Skip to content

Commit 9b3c6fd

Browse files
authored
!fix: password reset flow (#1566)
* feat(delete): enhance deleteCompassDataForMatchingUsers to include Google Calendar access check - Updated the deleteCompassDataForMatchingUsers function to accept a second parameter, gcalAccess, indicating whether the user has Google Calendar access. - This change allows for more granular control over the deletion process based on the user's Google Calendar connection status. * feat(auth): enhance AuthModal tests and URL handling for password reset flow - Introduced a new `RouteLocationMirror` component to synchronize URL state with the AuthModal. - Added `renderWithDayRedirectRoute` function to facilitate testing of the AuthModal with day-based routing. - Updated tests to verify that the reset password flow correctly preserves authentication parameters in the URL during redirects. - Implemented `updateCurrentUrlSearchParams` function to streamline URL parameter updates in the authentication flow. - Enhanced existing tests to ensure robust coverage of the new functionality and maintainability of the AuthModal component. * feat(auth): enhance AuthModal for password reset flow and status messaging - Introduced a new status message in the LogInForm to inform users of successful password resets. - Updated AuthModal logic to handle the new "loginAfterReset" view, improving user experience during the authentication process. - Enhanced tests for LogInForm to verify the display of status messages, ensuring accurate feedback for users. - Refactored related hooks and components to support the updated authentication flow and maintain clarity in the codebase. * feat(auth): enhance AuthModal tests for sign-up flow after password reset - Added a test to verify that clicking "Sign up" after a successful password reset correctly transitions the user to the sign-up view. - Updated error handling in the useZodForm hook to log errors in development mode, improving debugging capabilities during form submissions. * feat(env): rename LOCAL_WEB_URL to FRONTEND_URL across configuration and documentation * feat(env): streamline environment variable handling by removing staging and production URLs * refactor(email): extract new user tagging logic into EmailService.tagNewUserIfEnabled * docs: add error handling guide and engineering principles documentation * docs: reorganize documentation into categorical folders and add architecture, auth-sync, and recurring events guides * docs: reorganize documentation into categorical folders and add architecture, auth-sync, and recurring events guides * feat(docs): add coding conventions, deployment, and troubleshooting guides * fix(cli.utils): update domain retrieval logic to return host instead of hostname for non-local environments * Refactor recurring events documentation and sync process - Added section on Google Series Splits to recurring events handling documentation to clarify handling of incremental sync payloads. - Deleted outdated recurring events overview and sync documentation to streamline content and avoid redundancy. - Updated frontend data flow documentation to consolidate information and clarify event flow. - Revised principles documentation to align with repo guidance. * fix: supertokens middleware handler * refactor: optimize sync creation by removing Promise.all for sequential execution * fix: core tests
1 parent c970811 commit 9b3c6fd

51 files changed

Lines changed: 1144 additions & 828 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ packages/**/yarn.lock
1919
# DIRS #
2020
########
2121
# root
22-
.claude/settings.local.json
23-
.claude/worktrees/
22+
.claude/
2423
.idea/
2524
.mcp.json
2625
.vscode/

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Reporting a Vulnerability
44

5-
If you discover a security vulnerability in this project, please send an email to **tyler@switchback.tech** with the following details:
5+
If you discover a security vulnerability in this project, please send an email to <tyler@switchback.tech> with the following details:
66

77
- A description of the vulnerability
88
- Steps to reproduce (if applicable)

docs/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Docs
2+
3+
Internal documentation for engineers and agents working in the Compass repo.
4+
5+
Start with [AGENTS.md](../AGENTS.md) for repo rules, commands, and conventions. Use the docs below for codebase shape and subsystem behavior.
6+
7+
## Start Here
8+
9+
- [Agent Onboarding](./development/agent-onboarding.md)
10+
- [Repo Architecture](./architecture/repo-architecture.md)
11+
- [Feature File Map](./development/feature-file-map.md)
12+
- [Common Change Recipes](./development/common-change-recipes.md)
13+
14+
## Common Change Paths
15+
16+
- Auth or session behavior:
17+
[Frontend Runtime Flow](./frontend/frontend-runtime-flow.md),
18+
[Password Auth Flow](./features/password-auth-flow.md),
19+
[Google Sync And Websocket Flow](./features/google-sync-and-websocket-flow.md)
20+
- Event shape or recurrence behavior:
21+
[Event And Task Domain Model](./architecture/event-and-task-domain-model.md),
22+
[Recurrence Handling](./features/recurring-events-handling.md)
23+
- Local-first or storage behavior:
24+
[Offline Storage And Migrations](./features/offline-storage-and-migrations.md)
25+
- Backend routes and API behavior:
26+
[Backend Request Flow](./backend/backend-request-flow.md),
27+
[API Documentation](./backend/api-documentation.md),
28+
[Backend Error Handling](./backend/backend-error-handling.md)
29+
30+
## Runtime Flows
31+
32+
- [Frontend Runtime Flow](./frontend/frontend-runtime-flow.md)
33+
- [Google Sync And Websocket Flow](./features/google-sync-and-websocket-flow.md)
34+
- [Password Auth Flow](./features/password-auth-flow.md)
35+
36+
## Architecture And Domain
37+
38+
- [Repo Architecture](./architecture/repo-architecture.md)
39+
- [Event And Task Domain Model](./architecture/event-and-task-domain-model.md)
40+
- [Glossary](./architecture/glossary.md)
41+
- [Engineering Principles](./principles.md)
42+
43+
## Development And Operations
44+
45+
- [Env And Dev Modes](./development/env-and-dev-modes.md)
46+
- [Testing Playbook](./development/testing-playbook.md)
47+
- [Types And Validation](./development/types-and-validation.md)
48+
- [CLI And Maintenance Commands](./development/cli-and-maintenance-commands.md)
49+
- [Deploy](./development/deploy.md)
50+
- [Coding Conventions](./development/coding-conventions.md)
51+
52+
## Feature Deep Dives
53+
54+
- [Password Auth Flow](./features/password-auth-flow.md)
55+
- [Google Sync And Websocket Flow](./features/google-sync-and-websocket-flow.md)
56+
- [Recurrence Handling](./features/recurring-events-handling.md)
57+
- [Offline Storage And Migrations](./features/offline-storage-and-migrations.md)

docs/agent-onboarding.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

docs/event-and-task-domain-model.md renamed to docs/architecture/event-and-task-domain-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ These are UI-facing categories, not storage categories.
4545

4646
Many sync and parser decisions key off transitions between these states.
4747

48-
For the full recurring-event lifecycle, see [recurrence-handling.md](./recurrence-handling.md).
48+
For the full recurring-event lifecycle, see [Recurrence Handling](../features/recurring-events-handling.md).
4949

5050
## Update Scopes
5151

docs/architecture/glossary.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Glossary
2+
3+
Definition of terms used in the source code and documentation.
4+
5+
## Events
6+
7+
**Standalone Event**: An event that has a datetime and is NOT recurring. It represents a single occurrence.
8+
9+
**Grid Event**: An event that is assigned to a specific time slot on the calendar in the grid view. These events have both a date and time.
10+
11+
**Draft Event**: A calendar event that has pending changes that have not yet been persisted to the database. When a user makes changes to an event in the form, drags the event or resizes its times, the user is operating on a draft event. After the user clicks "Save", the draft event is persisted to the database, and the Draft Event goes away and is replaced with the Event.
12+
13+
**Someday Event**: These have `startDate` and `endDate` like regular timed events, but they have not yet been assigned to a specific time slot on the calendar in the grid. Instead, they are stored in the sidebar (Someday/Maybe list). These may be recurring or standalone.
14+
15+
**Base Event**: A _recurring_ event that defines the recurrence pattern. It has the series `RRULE` in the `recurrence` field and serves as a template for generating instances.
16+
17+
**Instance Event**: A _recurring_ event that is an individual occurrence of a base event. Instances are generated based on the base event's recurrence rule.
18+
19+
## Calendar Concepts
20+
21+
**Calendar**: A calendar is a collection of events. It is the main object in the application. In Compass, each user has their primary calendar.
22+
23+
**Calendar List**: Also known as sub-calendars. A calendar list is a collection of calendars. In Google Calendar, users can have multiple calendars (e.g., "Work", "Personal", "Holidays").
24+
25+
**Calendar View**: A calendar view is a way to view a calendar. Compass currently centers on:
26+
27+
- Day view
28+
- Week view
29+
- Now mode (focus on current task)
30+
- sidebar month widget / someday-month workflows
31+
32+
**Primary Calendar**: The main calendar associated with a user's Google account. Compass currently syncs only the primary calendar.
33+
34+
## Sync & Authentication
35+
36+
**Sync**: The Compass feature that allows users to sync their calendar data with other calendars like Google Calendar. Sync can be bidirectional (changes in Compass update Google Calendar and vice versa).
37+
38+
**Sync Channel**: A notification channel set up with Google Calendar that notifies Compass when events change. Managed via Google Calendar's watch API.
39+
40+
**nextSyncToken**: A token provided by Google Calendar API that allows incremental syncing. It represents the state of the calendar at a point in time.
41+
42+
**gAccessToken**: Google OAuth access token used to authenticate API requests to Google Calendar.
43+
44+
**gRefreshToken**: Google OAuth refresh token used to obtain new access tokens when they expire. Stored securely in MongoDB.
45+
46+
## Technical Terms
47+
48+
**Redux Store**: The centralized state management store for the React frontend. Contains all application state including events, user data, and UI state.
49+
50+
**Redux Saga**: Middleware for Redux that handles side effects (API calls, async operations) in a declarative way.
51+
52+
**Duck Pattern**: A Redux pattern that co-locates actions, reducers, and selectors in a single file (or directory) for a feature domain.
53+
54+
**WebSocket**: A communication protocol used for real-time bidirectional communication between the frontend and backend. Used to push updates when events change.
55+
56+
**Supertokens**: The authentication library used by Compass to manage user sessions, access tokens, and refresh tokens.
57+
58+
**MongoDB Collection**: A collection in MongoDB is similar to a table in a relational database. Compass uses collections for users, events, syncs, etc.
File renamed without changes.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ Runtime constraints from recipe overrides:
123123

124124
- successful password `signUpPOST` and `signInPOST` upsert the Compass user via `userService.upsertUserFromAuth(...)`
125125
- password `createNewRecipeUser` ensures SuperTokens external user-id mapping exists and points to a Mongo `ObjectId` string
126-
- password-reset emails are currently logged (dev/test) or logged as disabled (non-dev), not delivered by an external provider
126+
- password-reset links are rewritten to Compass app URLs before delivery
127+
- in `test`, reset links are logged instead of sent
128+
- outside `test`, delivery goes through SuperTokens email delivery
127129

128130
---
129131

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Backend Error Handling
2+
3+
Compass uses typed operational errors plus a centralized Express error handler.
4+
5+
## Source Files
6+
7+
- `packages/backend/src/common/errors/handlers/error.handler.ts`
8+
- `packages/backend/src/common/errors/handlers/error.express.handler.ts`
9+
- feature error metadata files under `packages/backend/src/common/errors/**`
10+
- `packages/core/src/errors/errors.base.ts`
11+
12+
## Main Pattern
13+
14+
Preferred backend pattern:
15+
16+
1. define reusable error metadata in the relevant feature file
17+
2. create a `BaseError` through `error(...)`
18+
3. let controller/service code throw that error
19+
4. let centralized Express handling turn it into the client payload
20+
21+
Example:
22+
23+
```ts
24+
import { AuthError } from "@backend/common/errors/auth/auth.errors";
25+
import { error } from "@backend/common/errors/handlers/error.handler";
26+
27+
throw error(AuthError.MissingRefreshToken, "Google connection required");
28+
```
29+
30+
## Client Payload Rules
31+
32+
For `BaseError`, backend responses are intentionally small:
33+
34+
- `result`: short result string
35+
- `message`: safe user-facing description
36+
37+
Internal details such as stack traces and operational flags stay server-side.
38+
39+
## Unexpected Error Rules
40+
41+
- non-`BaseError` values are routed through `handleExpressError(...)`
42+
- Google API errors get special handling for revoked tokens, invalid values, and full-sync recovery
43+
- programmer errors can terminate the process after logging
44+
45+
## Guidance
46+
47+
- Keep `result` short and stable.
48+
- Put technical detail in logs, not in the client payload.
49+
- Prefer reusing existing feature error metadata before inventing new names.
50+
- If the error should trigger special auth/sync behavior, verify both API handling and websocket side effects.
File renamed without changes.

0 commit comments

Comments
 (0)