-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update WorkOS example to use new AuthKit SDK #5394
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?
Update WorkOS example to use new AuthKit SDK #5394
Conversation
WalkthroughReplaces custom SSR AuthKit implementation with @workos/authkit-tanstack-react-start. Adds AuthKit middleware and provider, delegates callback handling to library, updates loaders to use getAuth/getSignInUrl, introduces a new “/client” demo route, adds Radix UI theme CSS, adjusts Vite SSR settings, and updates package dependencies and generated route types. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant R as Router (TanStack Start)
participant MW as AuthKit Middleware
participant L as Route Loader
participant AK as AuthKit (@workos/...-start)
participant IdP as WorkOS/Auth
U->>R: Navigate to protected route
activate R
R->>MW: Request middleware
MW->>AK: Parse session from cookies
AK-->>MW: Auth context (user/none)
MW-->>R: Continue request
R->>L: Run loader()
alt No user
L->>AK: getSignInUrl({ data: { returnPathname } })
AK-->>L: Authorization URL
L-->>U: Redirect to sign-in
U->>IdP: Authenticate
IdP-->>R: Redirect to /api/auth/callback?code&state
R->>AK: handleCallbackRoute (GET)
AK->>IdP: Exchange code for tokens
IdP-->>AK: Tokens
AK->>MW: Save session cookie
AK-->>U: Redirect to returnPathname
else User present
L-->>U: Return data (user)
end
deactivate R
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Command | Status | Duration | Result |
---|---|---|---|
nx affected --targets=test:eslint,test:unit,tes... |
❌ Failed | 6m 47s | View ↗ |
nx run-many --target=build --exclude=examples/*... |
✅ Succeeded | 1m 37s | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-10-07 14:03:24
UTC
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/nitro-v2-vite-plugin
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-static-server-functions
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (20)
examples/react/start-workos/package.json
(2 hunks)examples/react/start-workos/src/app.css
(1 hunks)examples/react/start-workos/src/authkit/serverFunctions.ts
(0 hunks)examples/react/start-workos/src/authkit/ssr/config.ts
(0 hunks)examples/react/start-workos/src/authkit/ssr/interfaces.ts
(0 hunks)examples/react/start-workos/src/authkit/ssr/session.ts
(0 hunks)examples/react/start-workos/src/authkit/ssr/utils.ts
(0 hunks)examples/react/start-workos/src/authkit/ssr/workos.ts
(0 hunks)examples/react/start-workos/src/routeTree.gen.ts
(8 hunks)examples/react/start-workos/src/routes/__root.tsx
(3 hunks)examples/react/start-workos/src/routes/_authenticated.tsx
(1 hunks)examples/react/start-workos/src/routes/_authenticated/account.tsx
(1 hunks)examples/react/start-workos/src/routes/api/auth/callback.tsx
(1 hunks)examples/react/start-workos/src/routes/client.tsx
(1 hunks)examples/react/start-workos/src/routes/index.tsx
(2 hunks)examples/react/start-workos/src/routes/logout.tsx
(1 hunks)examples/react/start-workos/src/start.ts
(1 hunks)examples/react/start-workos/src/vite-env.d.ts
(1 hunks)examples/react/start-workos/vite.config.ts
(2 hunks)packages/start-server-core/package.json
(1 hunks)
💤 Files with no reviewable changes (6)
- examples/react/start-workos/src/authkit/ssr/utils.ts
- examples/react/start-workos/src/authkit/ssr/session.ts
- examples/react/start-workos/src/authkit/ssr/interfaces.ts
- examples/react/start-workos/src/authkit/serverFunctions.ts
- examples/react/start-workos/src/authkit/ssr/workos.ts
- examples/react/start-workos/src/authkit/ssr/config.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
examples/react/start-workos/src/vite-env.d.ts
examples/react/start-workos/src/routes/index.tsx
examples/react/start-workos/src/routes/api/auth/callback.tsx
examples/react/start-workos/src/start.ts
examples/react/start-workos/src/routes/logout.tsx
examples/react/start-workos/src/routes/_authenticated/account.tsx
examples/react/start-workos/src/routeTree.gen.ts
examples/react/start-workos/src/routes/client.tsx
examples/react/start-workos/vite.config.ts
examples/react/start-workos/src/routes/_authenticated.tsx
examples/react/start-workos/src/routes/__root.tsx
examples/{react,solid}/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep example applications under examples/react/ and examples/solid/
Files:
examples/react/start-workos/src/vite-env.d.ts
examples/react/start-workos/src/routes/index.tsx
examples/react/start-workos/src/app.css
examples/react/start-workos/src/routes/api/auth/callback.tsx
examples/react/start-workos/src/start.ts
examples/react/start-workos/src/routes/logout.tsx
examples/react/start-workos/src/routes/_authenticated/account.tsx
examples/react/start-workos/src/routeTree.gen.ts
examples/react/start-workos/package.json
examples/react/start-workos/src/routes/client.tsx
examples/react/start-workos/vite.config.ts
examples/react/start-workos/src/routes/_authenticated.tsx
examples/react/start-workos/src/routes/__root.tsx
**/src/routes/**
📄 CodeRabbit inference engine (AGENTS.md)
Place file-based routes under src/routes/ directories
Files:
examples/react/start-workos/src/routes/index.tsx
examples/react/start-workos/src/routes/api/auth/callback.tsx
examples/react/start-workos/src/routes/logout.tsx
examples/react/start-workos/src/routes/_authenticated/account.tsx
examples/react/start-workos/src/routes/client.tsx
examples/react/start-workos/src/routes/_authenticated.tsx
examples/react/start-workos/src/routes/__root.tsx
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
Use workspace:* protocol for internal dependencies in package.json files
Files:
packages/start-server-core/package.json
examples/react/start-workos/package.json
packages/{*-start,start-*}/**
📄 CodeRabbit inference engine (AGENTS.md)
Name and place Start framework packages under packages/-start/ or packages/start-/
Files:
packages/start-server-core/package.json
🧬 Code graph analysis (7)
examples/react/start-workos/src/routes/index.tsx (3)
examples/react/start-workos/src/routes/__root.tsx (1)
Route
(12-39)examples/react/start-workos/src/routes/_authenticated.tsx (1)
Route
(4-14)examples/react/start-workos/src/routes/_authenticated/account.tsx (1)
Route
(5-27)
examples/react/start-workos/src/routes/api/auth/callback.tsx (2)
examples/react/start-workos/src/routes/__root.tsx (1)
Route
(12-39)examples/react/start-workos/src/routes/_authenticated.tsx (1)
Route
(4-14)
examples/react/start-workos/src/routes/_authenticated/account.tsx (3)
examples/react/start-workos/src/routes/__root.tsx (1)
Route
(12-39)examples/react/start-workos/src/routes/_authenticated.tsx (1)
Route
(4-14)examples/react/start-workos/src/routes/index.tsx (1)
Route
(6-13)
examples/react/start-workos/src/routeTree.gen.ts (2)
packages/router-core/src/router.ts (1)
Register
(97-102)examples/react/start-workos/src/router.tsx (1)
getRouter
(4-11)
examples/react/start-workos/src/routes/client.tsx (6)
examples/react/start-workos/src/routes/__root.tsx (1)
Route
(12-39)examples/react/start-workos/src/routes/_authenticated.tsx (1)
Route
(4-14)examples/react/start-workos/src/routes/_authenticated/account.tsx (1)
Route
(5-27)examples/react/start-workos/src/routes/api/auth/callback.tsx (1)
Route
(4-10)examples/react/start-workos/src/routes/index.tsx (1)
Route
(6-13)examples/react/start-workos/src/routes/logout.tsx (1)
Route
(4-9)
examples/react/start-workos/src/routes/_authenticated.tsx (3)
examples/react/start-workos/src/routes/__root.tsx (1)
Route
(12-39)examples/react/start-workos/src/routes/_authenticated/account.tsx (1)
Route
(5-27)examples/react/start-workos/src/routes/index.tsx (1)
Route
(6-13)
examples/react/start-workos/src/routes/__root.tsx (1)
examples/react/start-workos/src/components/sign-in-button.tsx (1)
SignInButton
(5-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (8)
examples/react/start-workos/vite.config.ts (2)
21-23
: LGTM!The
ssr.noExternal
configuration for@radix-ui/themes
is correct. Radix UI components need to be bundled during SSR rather than externalized, as they rely on client-side dependencies that must be transformed.
5-8
: No action required:.env.example
and README.md document the required environment variables.examples/react/start-workos/src/vite-env.d.ts (1)
1-6
: LGTM!The Vite client typings and CSS URL module declaration are correctly configured. This enables TypeScript to properly type CSS imports with the
?url
suffix (e.g.,import appCssUrl from './app.css?url'
), which is used in the root route.examples/react/start-workos/src/app.css (1)
1-1
: LGTM!The Radix UI themes stylesheet import is correctly configured and will be loaded via the URL import pattern in the root route.
examples/react/start-workos/src/start.ts (1)
8-13
: LGTM!The Start instance configuration correctly integrates the AuthKit middleware. The middleware will run on every server request, providing authentication context to route loaders and server functions.
examples/react/start-workos/src/routes/logout.tsx (1)
2-2
: LGTM!The import change from local implementation to the external SDK is correct and aligns with the PR's objective of using the official AuthKit SDK. The
signOut
function usage remains unchanged, preserving existing behavior.examples/react/start-workos/src/routes/api/auth/callback.tsx (1)
2-9
: LGTM!Delegating the OAuth callback handling to
handleCallbackRoute
from the external SDK simplifies the code significantly. The SDK now handles token exchange, session management, state validation, and redirects, reducing custom implementation complexity and potential security issues.packages/start-server-core/package.json (1)
79-79
: Vite devDependency is intentional:start-server-core
defines a"build": "vite build"
script and includesvite.config.ts
, so adding"vite": "^7.1.7"
is required.Likely an incorrect or invalid review comment.
"@tanstack/react-router-devtools": "^1.132.47", | ||
"@tanstack/react-start": "^1.132.47", | ||
"@workos-inc/node": "^7.45.0", | ||
"@workos/authkit-tanstack-react-start": "^0.1.0", |
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.
🧩 Analysis chain
Verify stability and breaking change expectations for the 0.1.x SDK.
The @workos/authkit-tanstack-react-start
package is at version ^0.1.0
, which indicates it's in early development. Pre-1.0 versions may introduce breaking changes in minor/patch releases. Consider pinning to an exact version or documenting this dependency risk.
🌐 Web query:
What is the latest stable version of @workos/authkit-tanstack-react-start and its release stability policy?
💡 Result:
I couldn't find any published npm package named "@workos/authkit-tanstack-react-start". Searches of npm/GitHub and WorkOS docs show WorkOS publishes AuthKit packages under @workos-inc (e.g. @workos-inc/authkit-react and @workos-inc/authkit-react-router), and the TanStack Start docs include a WorkOS example (not a package with the name you gave). [1][2][3]
If you meant a different package name, or a workspace/example repo, tell me the exact npm/GitHub package or repo and I’ll look it up. References:
- WorkOS AuthKit docs and packages. [1]
- WorkOS GitHub (authkit-react, authkit-nextjs, authkit-react-router). [2]
- TanStack Start React — WorkOS example (Start + WorkOS). [3]
Sources:
[1] https://workos.com/docs/authkit/react
[2] https://github.com/workos
[3] https://tanstack.com/start/latest/docs/framework/react/examples/start-workos
Correct invalid package dependency
The dependency "@workos/authkit-tanstack-react-start"
isn’t published on npm; WorkOS AuthKit packages live under the @workos-inc
scope (e.g. @workos-inc/authkit-react
). Update line 21 of examples/react/start-workos/package.json
to the correct package name and version.
🤖 Prompt for AI Agents
examples/react/start-workos/package.json around line 21: Replace the invalid
dependency "@workos/authkit-tanstack-react-start" with the correct scoped
package name and version, e.g. "@workos-inc/authkit-react": "^0.1.0" (or the
exact published version you need), then save and run npm/yarn install to update
lockfiles.
This PR updates the
start-workos
example to use the new@workos/authkit-tanstack-react-start
SDK instead of the custom implementation.What changed
getAuth()
andgetSignInUrl()
server functionsAuthKitProvider
for client-side auth state managementWhy
We built an official SDK that handles all the AuthKit integration details, so this example should demonstrate the recommended approach rather than a custom implementation. Makes the example cleaner and easier to follow.
Summary by CodeRabbit