# user (https://docs.salla.dev/twilight/react/api/modules/user)



Use `user` to find out who the customer is. Most of the time you want the [`useUser()`](https://docs.salla.dev/twilight/react/api/authentication-and-scope#skip-calls-that-need-a-login) hook, which runs this query only when a token exists and returns `isLoggedIn` beside the result.

```tsx title="app/components/Greeting.tsx"
import { useQuery } from '@tanstack/react-query';
import { useUser } from '@salla.sa/twilight-theme-engine/hooks/useUser';
import { user } from '@salla.sa/twilight-theme-engine/api/user';

export function Greeting() {
  const { isLoggedIn } = useUser();
  const { data: me } = useQuery({
    ...user.queries.current(),
    enabled: isLoggedIn,
  });

  return <p>{me ? `Hello ${me.first_name}` : 'Hello'}</p>;
}
```

Editing the profile is in [`profile`](https://docs.salla.dev/twilight/react/api/modules/profile).

## Methods [#methods]

| Method | Parameters | Returns                 | Request         | Login needed                    |
| ------ | ---------- | ----------------------- | --------------- | ------------------------------- |
| `get`  | none       | `Promise<User \| null>` | `GET auth/user` | Yes (returns `null` without it) |

The result is the response data plus `type: 'user'`.

## Queries [#queries]

| Query                    | Key                   |
| ------------------------ | --------------------- |
| `user.queries.current()` | `['user', 'current']` |

The key includes neither the locale nor the scope, and it is the same for every customer. Reset it when the customer signs in or out:
`queryClient.invalidateQueries({ queryKey: user.queries.current().queryKey })`.

## Gotchas [#gotchas]

* `get` never throws. Any failure (guest, expired token, network error) is logged with `console.debug` and becomes `null`, so you cannot tell "guest" from "request failed" by the result.
* Because errors are swallowed, the query never enters an error state and does not retry.
* After sign-out, clear this key and also `['orders']` and `['wishlist']`, so a cached customer does not linger.

## See also [#see-also]

* [profile](https://docs.salla.dev/twilight/react/api/modules/profile)
* [Authentication and scope](https://docs.salla.dev/twilight/react/api/authentication-and-scope)
* [order](https://docs.salla.dev/twilight/react/api/modules/order)
