# Impersonation

Impersonation lets trusted admins **see the app as someone else** — for support and testing.

There are **two types**. They work differently.

---

## Type 1: User impersonation

**Who:** Any employee or user (except super admin targets)  
**Where to start:** Employees or Users page → **mask icon**

### Steps

1. Find the person on **Employees** or **Users**.
2. Click **Impersonate** (mask icon).
3. A **yellow banner** appears: "Viewing as [name]".
4. Browse the app as they would see it.
5. Click **Exit impersonation** on the banner.

### What changes

- You become that user's identity (name, role, permissions).
- Your real account is stored safely as the "actor".
- If they are a business user, you also get their business context.

### Exit

Click **Exit impersonation** on the yellow banner. You return to your own account.

---

## Type 2: Business impersonation

**Who:** Super admin (or users with `BUSINESSES_IMPERSONATE`)  
**Where to start:** Business detail page → **Impersonate business**

### Steps

1. Go to **Businesses** and open a business.
2. Start business impersonation.
3. Optionally select a **staff member** to view as (from the blue banner dropdown).
4. Sidebar switches to **business panel**.
5. Click **Exit** on the blue banner.

### What changes

- You keep **your own** admin identity.
- A **business context** is added (business name, logo, permissions).
- You see the business panel, not the main admin dashboard.

### Switch staff (while impersonating)

Use the dropdown on the blue banner to view as Owner, Manager, or another staff member without leaving the business.

---

## Comparison

| | User impersonation | Business impersonation |
|---|-------------------|------------------------|
| **Banner color** | Yellow | Blue |
| **Your identity** | Replaced by target user | Stays as you |
| **Use case** | Debug a specific login | Explore a business setup |
| **Exit** | Yellow banner → Exit | Blue banner → Exit |
| **Sidebar** | Target user's view | Business panel |

> Do not run both at the same time. Starting one should clear the other.

---

## Permissions

| Type | Permission |
|------|------------|
| User | `USERS_IMPERSONATE` |
| Business | `BUSINESSES_IMPERSONATE` |

Super admin can always impersonate.

---

## Safety tips

- Only impersonate when needed for support or testing.
- Always **exit** when finished.
- Do not change passwords or delete data while impersonating unless intentional.
- Tell the user if you accessed their account for support.

---

## Troubleshooting

| Problem | Try |
|---------|-----|
| Still see admin dashboard after business impersonate | Go to `/dashboard/business` or refresh |
| Wrong permissions while impersonating | Check target user's global + business roles |
| Can't impersonate super admin | Blocked by design |
| Banner won't go away | Click Exit; if stuck, sign out and sign back in |

---

## Related guides

- [Employees](./03-employees.md)
- [Businesses](./05-businesses.md)
- [Business panel](./06-business-panel.md)
