Sync Parse.user with db

I’m implementing google firebase cloud messaging in my app to send notifications, so when i generate a user key client side I save it to the user object via a cloud function for security, i want to also update the local storage parse object with that key to persist the key between sessions without having to logout then login.

Is there a way to force the parse.user object in local storage to sync with db?

I had a similar scenario, changing the current user’s props in CloudCode and not getting this change reflected in Parse.User.current. My fix was to manually fetch the current user object, which also seems to update the localStorage data:

async function updateUser(userId: string, params: Params) {
  // ... call CloudCode function ...

  // Re-fetch current user to update Parse's cached data in localStorage
  if (userId === Parse.User.current()?.id) {
    // await can be omitted here if an "eventual" update is good enough for you
    await Parse.User.current()?.fetch() 
  }
}

hth

Thanks for your help, I tried it but I’m getting 404 not found error despite the user id in the error fetch url exists in the db

Might be that your query is executed without the correct access rights. In my scenario the current user is logged in, so the fetch call users this user’s session token. Make sure that you have that user logged in when making that call.