How to update `api/auth/get-session` with new session data?
I am updating the users table with the new name but accessing
api/auth/get-session
gives the old data. Is there a way to trigger an update when the database is updated so session data is also updated?
I am using tanstack start. ```import { createAPIFileRoute } from '@tanstack/react-start/api'
import { auth } from '@/lib/auth'
export const APIRoute = createAPIFileRoute('/api/auth/$')({
GET: ({ request }) => auth.handler(request),
POST: ({ request }) => auth.handler(request),
})18 Replies
send ur code
The server function in
__root.tsx
and this is how I invalidate the session after database update:
first I recommend using
authCllient.updateUser
to update the user name. It'll handle invalidating and updating the cache. If you need to manually update, you can pass disableCookieCache
as a query param when you call getSession
to update the cache@bekacru thanks for the response, is it possible the
queryClient.invalidateQueries
invalidate the cache?
I am building a profile page where users can edit their name, so upon submission I want to update the sessionIt should unless you've enabled cookieCache. But you can also just call
authClient.updateUser
which invalidate the cache for you@bekacru Yes, you were right, in my config I had it enabled, after disabling it everything gets invalidated
is that the only way? i have to process image upload at server side to get the url. currently i'm doing this
or at least i could modify the client's session?
you can use database hooks instead
but this should work as well, if you're using
nextCookies
or setting cookies manually after the responsei don't get this, but i'm using nextjs. should it work automatically? i'm not even sure how to manually set it
but with database hook, how can i make it accept
File
object?
bruh, refetch
function exist in authClient.useSession
but it would nice if i could update the session without refetchingIf you are using database hook you can upload the image and directly get the url from that and update your fields with that url
but updating user with
File
will make typescript complain for not passing a stringNo your file field is gonna be string I mean link of the uploaded file which is uploaded before hand
uploading it in client side wouldn't work and it's not safe
That's up to your storage service if it provide an API keys or any kind pre signed url stuff that needs to process from server or client side plus database is not running on client side as well
File
is from the browser uploaded by the user, and then get its data to upload it to s3 now if the process is successful i couldn't get its url and update user
so it wouldn't be a string until i upload itYeah write your logic there at db hook and get the url back since all pre signing will handle s3
He is suggesting to upload the image first and then call
updateUser
. Which would be a bit slow since you'd have 2 round trips instead of one
If you're using nextjs, just keep on what you're currently doing. If you munted nextCookies
plugin in your auth config, it should update the cache for you when you call auth.api.updateUser
thanks, i have missing configuration
but nextCookies only works with server actions, but not on api calls