#convex auth + tanstack start

6 messages · Page 1 of 1 (latest)

lucid panther
#

Hello guys im playing with convex and tanstack start, want to implement authentication, this is example page ```
export const Route = createFileRoute('/page')({
component: SignIn,
loader: ({ context }) =>
context.queryClient.ensureQueryData(authQueries.currentUser()),
})

function Component() {
const { data: user } = useSuspenseQuery(authQueries.currentUser())
return (
<div>
{JSON.stringify(user)}
hello
<AuthForm type="signIn" />
</div>
)
}
this is how i get current usercurrentUser: () => convexQuery(api.auth.getCurrentUser, {}), getCurrentUser is straight from docs:export const getCurrentUser = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx)
console.log(userId)
if (!userId) return null
return await ctx.db.get(userId)
},
}) My problem is that inside loader the user is null, so inside component i can see small delay then data is available. this is my router setup: const router = routerWithQueryClient(
createTanStackRouter({
routeTree,
defaultPreload: 'intent',
defaultErrorComponent: DefaultCatchBoundary,
defaultNotFoundComponent: () => <NotFound />,
context: { queryClient },
Wrap: ({ children }) => (
<ConvexAuthProvider client={convexQueryClient.convexClient}>
<ConvexProvider client={convexQueryClient.convexClient}>
{children}
</ConvexProvider>
</ConvexAuthProvider>
),
}),
queryClient,
)```

lucid panther
#

Is it possible to get current user id on the server side right now?

storm bear
#

Convex Auth is in beta, this is early days — but this is coming! I'm digging into this this week.

lucid panther
craggy urchin
storm bear