# iCal Feeds

> Subscribe to a personal calendar feed of approved leave requests

## Overview

Each user gets a personal iCal feed URL that contains their approved leave requests. Subscribe to it from Google Calendar, Apple Calendar, or Outlook to see absences alongside your regular schedule.

The feed updates automatically — when a new leave request is approved, it appears in your calendar without any action.

## Admin Setup

Before users can generate feed URLs, an admin must set the `ICAL_SECRET` environment variable. This secret is used to generate secure, per-user URLs.

Add to `.env.local`:

```dotenv
ICAL_SECRET=a-long-random-string
```

Generate a random value with:

```bash
openssl rand -hex 32
```

> **Warning:** Changing `ICAL_SECRET` invalidates all existing feed URLs. Every user will need to re-copy their URL and update their calendar subscriptions.

## Get Your Subscription URL

1. Go to **Profile → Connected Services**.
2. In the **Calendar** section, you'll see your personal iCal feed URL.
3. Click **Copy URL** to copy it to your clipboard.

The URL looks like:
```
https://your-domain.com/api/calendar/{userId}/{hash}.ics
```

![Profile settings showing the Connected Services section with calendar subscription URL](/assets/images/docs/user-profile-ical.png)
*Your personal iCal feed URL in the Connected Services section*

## Subscribe in Google Calendar

1. Open [Google Calendar](https://calendar.google.com).
2. On the left sidebar, click the **+** next to "Other calendars".
3. Select **From URL**.
4. Paste the iCal feed URL.
5. Click **Add calendar**.

Google Calendar syncs external feeds roughly every 12–24 hours. New leave requests may take a while to appear.

> **Tip:** Google Calendar's sync interval is not configurable. If you need faster updates, use Apple Calendar or Outlook, which tend to refresh more frequently.

## Subscribe in Apple Calendar

1. Open **Calendar** on macOS.
2. Go to **File → New Calendar Subscription…**
3. Paste the iCal feed URL and click **Subscribe**.
4. Set the auto-refresh interval (e.g. every hour) and click **OK**.

On iOS: go to **Settings → Calendar → Accounts → Add Account → Other → Add Subscribed Calendar** and paste the URL.

## Subscribe in Outlook

1. Open [Outlook on the web](https://outlook.office.com/calendar).
2. Click **Add calendar** in the sidebar.
3. Select **Subscribe from web**.
4. Paste the iCal feed URL, give it a name, and click **Import**.

## Regenerate Your URL

If you suspect your feed URL has been shared or compromised, you can regenerate it:

1. Go to **Profile → Connected Services**.
2. In the **Calendar** section, click **Regenerate URL**.
3. Copy the new URL and update your calendar subscriptions.

The old URL stops working immediately.

> **Warning:** After regenerating, you must update the URL in every calendar app where you subscribed. The old URL will return an error.

