Sanity CMS: Get current user from datastore

454 Views Asked by At

I'm trying to fetch the current user in Sanity CMS.

I found this code snippet which demonstrates use of userStore

But I don't understand how I can configure my project to accept this module lookup

import userStore from 'part:@sanity/base/user';

It throws an import error Cannot find module 'part:@sanity/base/user'. Which makes sense as its a non standard node module.

  1. How can I resolve this so the module is found?
  2. Or alternatively anyone know another way to fetch the current user?

Inspecting that @sanity source I can see base/lib/datastores which has a userStore it's just not obvious how to consume this.

1

There are 1 best solutions below

0
On

So this example hook works and returns the User. Sanity is taking care of the module resolution. It's an IDE error not a runtime error in Sanity.

(╯°□°)╯︵ ┻━┻

Their advice is to ignore these un resolved module warnings for part imports.

  "eslintConfig": {
    "rules": {
      "import/no-unresolved": [2, { "ignore": ["^(all|part):"] }]
    }
  },