# gpm whoami

Display information about the currently authenticated user.

## Usage

```bash
gpm whoami [--registry <url>]
```

## Flags

| Flag               | Description                              | Default     |
| ------------------ | ---------------------------------------- | ----------- |
| `--registry <url>` | Registry URL to check authentication for | From config |

## Description

The `gpm whoami` command displays information about the currently authenticated user, including username and registry details. This command is useful for verifying authentication status and checking which user account is currently active.

### Information Displayed

* **Username**: Currently authenticated user
* **Registry**: Registry URL being used
* **Authentication Status**: Whether user is logged in
* **Token Status**: Whether valid token exists

## Examples

### Basic Usage

```bash
# Check current user
gpm whoami
```

### Specific Registry

```bash
# Check user for specific registry
gpm whoami --registry https://company.gpm.sh
```

## Output

### Authenticated User

```
User Information
─────────────────────────────────────────
Username: myusername
Registry: https://registry.gpm.sh
Status:   Authenticated
─────────────────────────────────────────
```

### Not Authenticated

```
Authentication Status
─────────────────────────────────────────
Registry: https://registry.gpm.sh
Status:   Not authenticated
─────────────────────────────────────────
Run 'gpm login' to authenticate
```

### JSON Output

```bash
# Get user info in JSON format
gpm whoami --json
```

```json
{
  "username": "myusername",
  "registry": "https://registry.gpm.sh",
  "authenticated": true,
  "message": "User information retrieved successfully"
}
```

## Registry-Specific Information

### Global Registry

```bash
# Check global registry authentication
gpm whoami --registry https://registry.gpm.sh
```

### Tenant Registry

```bash
# Check tenant registry authentication
gpm whoami --registry https://company.gpm.sh
```

## Use Cases

### Authentication Verification

```bash
# Verify before publishing
gpm whoami
gpm publish --access=private
```

### Debugging Authentication Issues

```bash
# Check authentication status
gpm whoami --verbose
```

### CI/CD Authentication Check

```bash
# Verify authentication in CI
if gpm whoami --json | grep -q '"authenticated": true'; then
  echo "Authentication verified"
else
  echo "Authentication required"
  exit 1
fi
```

## Error Handling

### Common Scenarios

* **Not authenticated**: User is not logged in
* **Invalid token**: Stored token is invalid or expired
* **Network error**: Cannot connect to registry
* **Registry not found**: Invalid registry URL

### Troubleshooting

1. **Not authenticated**: Run `gpm login` to authenticate
2. **Invalid token**: Clear authentication with `gpm logout` and re-login
3. **Network issues**: Check internet connection and registry URL
4. **Registry not found**: Verify registry URL is correct

## Security Considerations

### Information Disclosure

* Only displays username, not sensitive information
* Does not expose authentication tokens
* Safe to use in logs and CI/CD systems

### Token Validation

* Validates token with registry server
* Reports invalid or expired tokens
* Automatically handles token refresh if supported

## Related Commands

* [`gpm login`](/cli-reference/cli/authentication/login.md) - Sign in to registry
* [`gpm logout`](/cli-reference/cli/authentication/logout.md) - Sign out from registry
* [`gpm config`](/cli-reference/cli/configuration/config.md) - Manage configuration settings

## See Also

* [Authentication Overview](/cli-reference/cli/authentication.md)
* [Registry Configuration](https://github.com/gpm-sh/docs/blob/main/packages/registry-resolution.md)
* [Security Best Practices](https://github.com/gpm-sh/docs/blob/main/troubleshooting/common-issues.md#security)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gpm.sh/cli-reference/cli/authentication/whoami.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
