-
Notifications
You must be signed in to change notification settings - Fork 0
Extract authentication business logic and remove deprecated code #6
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
base: main
Are you sure you want to change the base?
Conversation
…ended
- Emphasize toolkit-first: Core + Operations are primitives
- AuthService is 'one way' not 'the way' to orchestrate
- Update exports: Primitives first, orchestration second (optional)
- Remove prescriptive language ('recommended', 'advanced')
- Acknowledge AuthService is used by TanStack Start as proof it works
- Preserve toolkit philosophy: frameworks choose their orchestration
- Remove 'toolkit' language from all documentation - Frame AuthService as public API, not 'one option' - Label Core + Operations as 'internal layers' (advanced use only) - Update package.json description to be accurate - Reorder exports: AuthService first, internals last - Acknowledge what this is: framework-agnostic library with adapter pattern - Stop pretending Core + Operations are composable primitives
03d1042 to
b802f54
Compare
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.
Pull Request Overview
This PR successfully extracts WorkOS authentication business logic into a framework-agnostic library, replacing the deprecated factory pattern with a clean service-based architecture. The refactor introduces improved type safety through discriminated unions and establishes clear separation of concerns between public API (AuthService) and internal implementation (AuthKitCore, AuthOperations).
Key changes:
- Introduced
AuthServiceas the main public API withcreateAuthService()factory - Removed deprecated
SessionManagerandcreateAuthKitFactory()(~500 lines) - Enhanced type safety with discriminated union
AuthResulttype (eliminates optional chaining) - Updated dependencies (jose 6.1.2, vitest 4.0.10, typescript 5.9.3)
Reviewed Changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/service/factory.ts | New factory function with lazy initialization for AuthService creation |
| src/service/AuthService.ts | New main public API coordinating core logic, operations, and storage |
| src/operations/AuthOperations.ts | New operations layer handling WorkOS API calls (signOut, refresh, URLs) |
| src/core/AuthKitCore.ts | New core business logic layer (JWT, encryption, refresh orchestration) |
| src/core/session/types.ts | Enhanced with discriminated union AuthResult type for better type safety |
| src/core/session/CookieSessionStorage.ts | Added secure flag inference and SameSite capitalization for Safari |
| src/index.ts | Reorganized exports with clear public API vs internal layers distinction |
| package.json | Updated dependencies and version to 0.2.0-beta.0 |
| README.md | Complete rewrite explaining architecture, storage adapter pattern, and usage |
| pnpm-lock.yaml | Dependency updates reflecting package.json changes |
| src/core/session/SessionManager.ts | Removed deprecated SessionManager class |
| src/core/createAuthKitFactory.ts | Removed deprecated factory pattern |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The 'toolkit' framing was fine. Overthinking the semantics added no value. Keep the good parts from original update: philosophy, architecture, examples.
cfaad70 to
61ef064
Compare
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.
Pull Request Overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- replace vague "toolkit primitives" with "framework-agnostic authentication service" - update "toolkit API" to "public API" for clarity - add missing comment to empty catch block in token validation
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.
Pull request overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| config: AuthKitConfig, | ||
| ) => SessionStorage<TRequest, TResponse>; | ||
| clientFactory?: (config: AuthKitConfig) => WorkOS; | ||
| encryptionFactory?: (config: AuthKitConfig) => SessionEncryption; |
Copilot
AI
Nov 24, 2025
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.
The parameter name has a typo: confg should be config.
Co-authored-by: Copilot <[email protected]>
5c753cc to
881cbd0
Compare
Greptile OverviewGreptile SummaryThis PR successfully extracts authentication business logic into a cleaner, more maintainable architecture with three distinct layers: Key improvements:
Breaking changes:
Security posture:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant App as Framework App
participant AS as AuthService
participant Storage as SessionStorage
participant Core as AuthKitCore
participant Ops as AuthOperations
participant WorkOS as WorkOS API
Note over App,WorkOS: Authentication Flow (withAuth)
App->>AS: withAuth(request)
AS->>Storage: getSession(request)
Storage-->>AS: encryptedSession
AS->>Core: decryptSession(encryptedSession)
Core-->>AS: session (tokens + user)
AS->>Core: validateAndRefresh(session)
Core->>Core: verifyToken(accessToken)
Core->>Core: isTokenExpiring(accessToken)
alt Token valid and not expiring
Core-->>AS: valid session, no refresh
else Token invalid or expiring
Core->>WorkOS: authenticateWithRefreshToken()
WorkOS-->>Core: new tokens and user
Core->>Core: encryptSession(newSession)
Core-->>AS: refreshed session data
end
AS-->>App: AuthResult with optional refresh
Note over App,WorkOS: OAuth Callback Flow
App->>AS: handleCallback(request, response, options)
AS->>WorkOS: authenticateWithCode(authCode)
WorkOS-->>AS: tokens and user data
AS->>Core: encryptSession(session)
Core-->>AS: encryptedSession
AS->>Storage: saveSession(response, encryptedSession)
Storage-->>AS: updated response with cookie
AS-->>App: response with return path
Note over App,WorkOS: Sign Out Flow
App->>AS: signOut(sessionId, options)
AS->>Ops: signOut(sessionId, options)
Ops->>WorkOS: getLogoutUrl(sessionId)
WorkOS-->>Ops: logoutUrl
Ops->>Ops: buildClearCookieHeader()
Ops-->>AS: logout URL and clear cookie
AS-->>App: logout data for redirect
|
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.
18 files reviewed, no comments
Summary
Extract authentication business logic into reusable classes and remove deprecated factory pattern. Provides clean API for building framework-specific WorkOS authentication packages.
Key Changes
New API:
createAuthService({ sessionStorageFactory })- Create auth instanceAuthService- Main API (withAuth, signOut, getSignInUrl, etc.)AuthResult- TypeScript-safe auth checksRemoved:
createAuthKitFactory()- DeprecatedSessionManager- DeprecatedInternal architecture:
AuthKitCore- JWT verification, session encryption, refresh logicAuthOperations- WorkOS API operationsBreaking Changes
1. Factory function renamed:
2. withAuth returns discriminated union:
3. AuthResult type:
Testing
Documentation