> ## Documentation Index
> Fetch the complete documentation index at: https://useaward.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# useUser

The useUser hook is a convenient way to access the current user data where you need it. This hook provides the user data and authorize method to manage the current active user.

# Authorize

## Register User

When user is registered, the user's uuid will be storied in the storage. This will allow to identify the user in the future. Please note that you also need to store it in the database in case the user clears the storage.

```jsx theme={null}
import { useUser } from '@useawards/useaward-expo';

function Main() {
  const { register, user } = useUser();

  const handleRegister = async () => {
    const response = await register({
      email: 'reinis3@test.com',
      name: "Reinis Test",
    })
  }

  return (
    <>
    </>
  );
}
```

## Authorize existing user

You can use stored users uuid to authorize the user.

```jsx theme={null}
import { useUser } from '@useawards/useaward-expo';

function Main() {
  const { authorize } = useUser();

  useEffect(() => {
    const authorizeUser = async (uuid) => {
      await authorize()
    }

    // get stored users uuid
    ...

    authorizeUser(userUuid)
  }, [])

  ...
}
```

## Authorized User

You can get the current authorized user by using the `user` property.

```jsx theme={null}
function Main() {
  const { isLoading, user } = useUser();

  if (isLoading) {
    return <p>Loading...</p>
  }

  return (
    <>
      <p>{user.name}</p>
    </>
  );
}
```

The `useUser` hook returns the current user object, which includes the name and email properties. If no user is currently logged in, the hook will return null.

You can use the `useUser` hook anywhere within a component tree that is wrapped in the UseawardsProvider. If there is no UseawardsProvider in the tree, the useUser hook will throw an error.
