iam update user profile but session dont update ho...
# support-questions-legacy
p
iam update user profile but session dont update how to client update session ? iam search docs but dont find :/
r
hey @productdevbook
what are you updating in the user profile? And how are you doing that?
p
my your db update custom graphql
this backend
r
i have no idea what you are trying to say. Sorry
p
When you log in for the first time, the above session data comes. It then updates its profile inside, this profile is our own user db. If I update the session request, the above code will work. But how do I renew the session on the client?
r
you can use mergeIntoAccessTokenPayload function or updateSessionData function on the session container.
Is there an easier way to do this on the client?
r
when you say client, do you mean frontend or backend?
you can't change session info on the frontend
p
Can't I change it while refreshing?
r
for that, you still need to make the change on the backend
p
hmm, So I need to set up the update structure in the backend for the access tokens to be renewed. ?
or now write ? thats true
client page refresh but dont reload access token
Is there a separate structure to refresh this in the client?
r
no. You don't need to override the updateSessionData function
so im not really sure what you are trying to achieve here. If you could explain clearly, that would help
p
login
createNewSession
custom
accessTokenPayload
add username etc my custom db added. but after login user settings update db username and refresh page dont new data
accessTokenPayload
because dont update session
It is necessary to request the session again and get it from the new
accessTokenPayload
database.
r
ok. So first, you don't need to change sessionData at all here. Just changing accessTokenPayload is fine. Second, when you update the user's data in the db, you should also update their session's accessTokenPayload using session.mergeIntoAccessTokenPayload function. See this: https://supertokens.com/docs/session/common-customizations/sessions/claims/access-token-payload#post-session-creation
p
Thank you now working ❤️
Copy code
ts
  server.post('/updateinfo', {
    preHandler: verifySession(),
  }, async (req: SessionRequest, res) => {
    const session = req.session
    if (!session)
      throw new Error('Session not found')

    const dbUser = await storage.userRepo.getUserBySuperTokenId({ superTokensUserId: session.getUserId() })
    if (!dbUser) {
      throw new Error(
        'Creating a new session failed',
      )
    }

    await session!.mergeIntoAccessTokenPayload(
      { username: dbUser.username },
    )
    res.send({ message: 'successfully updated access token payload' })
  })
r
awesomr