Skip to content

How to get current user for inline template values? #3777

Discussion options

You must be logged in to vote

The initialValue callback function should now receive a context object that includes the current user. I haven't tested this code, but it should be something like this:

{
          type: "reference",
          to: [{ type: "redaktor" }],
        },
      ],
      validation: (Rule) => Rule.required().unique(),
      initialValue: async (params, context) => {
        const {currentUser: user, getClient} = context
        const client = getClient({apiVersion: '2022-10-20'})
        const foundRedaktor = await client.fetch( // TODO How to fetch using a client in the context of the studio without a React-component
          `*[_type == "redaktor" && navn == '${user.name}'][0]`
        );

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rexxars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants