Refreshing `useAuth()` in Custom Component

default discord avatar
loaialsharee10 months ago
2

I have been following this sample code from

select

documentation:

https://payloadcms.com/docs/fields/select#:~:text=const%20%7B%20user%20%7D%20%3D%20useAuth()%3B

Basically, I have created a custom select field that holds roles for different users, but, I have noticed that after changing the role of the user there,

user

object coming from

useAuth()

does not update the user data (i.e. keeps the old role of the user before the update) unless I logout and login again then it will only be updated. Is there a way on how I can refresh the user object there so it can update dynamically once the user's role is updated?

  • discord user avatar
    jarrod_not_jared
    10 months ago

    There is an undocumented function exposed through the useForm hook,

    fetchFullUser

    that you can call after updating the user.

    const { fetchFullUser } = useForm()
  • default discord avatar
    loaialsharee10 months ago

    Thank you @jarrod_not_jared! I'll give it a try 🙂

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.