Skip to content

Conversation

@erquhart
Copy link
Contributor

@erquhart erquhart commented Oct 31, 2025

  • Adds support and patterns for SSR compatible auth
  • Adds redirect support

See /account page changes for patterns, /builder page changes for redirects

Issues I'd like some input on:

  • We need a way to continue showing Query data from ssr until authentication state resolves for select queries.
  • There's a flash of white when the user first authenticates, presumably due to a hydration mismatch, but I haven't found a clear fix for it

@netlify
Copy link

netlify bot commented Oct 31, 2025

👷 Deploy request for tanstack pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 4d88d73

"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"convex": "^1.25.4",
"convex-oss-stats": "link:../../../erquhart/convex-oss-stats",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to work.

Copy link
Contributor Author

@erquhart erquhart Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updates the convex package and removes a non-existent file based package, was left in accidentally from a while ago. The actual package is @erquhart/convex-oss-stats, that dependency is still in place.

}),
}),
beforeLoad: async (ctx) => {
requireAuth(ctx)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utility that checks for a user id, and if none is present, throws a redirect with the current location in the redirectTo query param.

Comment on lines +27 to +31
await ctx.context.queryClient.ensureQueryData(
convexQuery(api.auth.getCurrentUser, {})
)
await ctx.context.queryClient.ensureQueryData(
convexQuery(api.llmKeys.listMyLLMKeysForDisplay, {})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to parallelize these.

Comment on lines +44 to +54
const getAuth = createServerFn({ method: 'GET' }).handler(async () => {
const { createAuth } = await import('../../convex/auth')
const cookieNames = getCookieNames(createAuth)
const cookieAuth = getAuthFromCookie(getCookie(cookieNames.convexJwt))
if (cookieAuth) {
return cookieAuth
}
if (getCookie(cookieNames.sessionToken)) {
return await fetchAuth(getRequest())
}
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses Convex jwt from cookie if it exists and is not expired, otherwise fetches a new one, which relies on the longer lived session cookie. If that fails the user is considered unauth.

Comment on lines -535 to -552
<Authenticated>
<UserSettings />
</Authenticated>
<Unauthenticated>
<div className="bg-white dark:bg-black/30 rounded-lg shadow-lg p-8 text-center w-[100vw] max-w-sm mx-auto">
<h2 className="text-xl font-semibold text-gray-900 dark:text-white mb-4">
Sign In Required
</h2>
<p className="text-sm text-gray-600 dark:text-gray-300 mb-6">
Please sign in to access your account settings.
</p>
<Link to="/login">
<button className="text-sm font-medium bg-black/80 hover:bg-black text-white dark:text-black dark:bg-white/95 dark:hover:bg-white py-2 px-4 rounded-md transition-colors">
Sign In
</button>
</Link>
</div>
</Unauthenticated>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped this as the page won't show for unauthenticated users.

@erquhart erquhart requested a review from jherr November 3, 2025 00:35
@jherr jherr marked this pull request as ready for review November 3, 2025 17:47
@jherr jherr merged commit 835d62f into TanStack:create-ui Nov 3, 2025
1 of 2 checks passed
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