Inforario can push your entire parsed UTM schedule to Google Calendar as recurring weekly events, one per class session, covering the full academic semester you specify. The integration is built on a Supabase Edge Function (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DavidCevallos15/inforario-IA-null/llms.txt
Use this file to discover all available pages before exploring further.
google-calendar-sync) that runs server-side, automatically refreshes expired OAuth2 tokens, and inserts events directly through the Google Calendar REST API — so your timetable appears in Google Calendar just as it does in Inforario: subject name, classroom location, teacher, and a weekly recurrence rule until the semester ends.
How It Works End-to-End
Connect Google Calendar
The user authenticates with their Supabase account and links Google Calendar. The OAuth2 flow stores both an
access_token and a refresh_token in the user_calendar_tokens table in Supabase.Open the Calendar Modal
From the dashboard, the user clicks Export / Sync Calendar. The
CalendarModal opens and checks the user_calendar_tokens table via the useCalendarStatus hook to confirm the Google account is linked.Build Calendar Events
Inforario calls
buildCalendarEventsFromSchedule(schedule, semesterStart, semesterEnd, timeZone), which iterates over every ClassSession in the parsed schedule and returns an array of CalendarEventInput objects — each carrying a computed DTSTART, DTEND, and a weekly RRULE that repeats until the end of semester.Invoke the Edge Function
syncCalendarEvents({ calendarId, events }) forwards the built events to the google-calendar-sync Supabase Edge Function via supabase.functions.invoke.Edge Function Inserts Events
The Edge Function authenticates the caller, reads their tokens from
user_calendar_tokens, refreshes the access_token if it is within 60 seconds of expiry, then inserts each event via POST /calendar/v3/calendars/{calendarId}/events. If a 401 or 403 is returned for any single event, it performs a one-time token refresh and retries before propagating the error.Prerequisites
Supabase Account
The user must be signed in with a valid Supabase session. Guest users (identified by a
dev- device ID) are rejected at the UUID-validation gate in supabaseClient.ts.Google Calendar Connected
The user must have completed the Google OAuth2 flow so that a row exists in
user_calendar_tokens for their user ID. The useCalendarStatus hook surfaces this status in the UI.API Reference
CalendarEventInput
The data shape passed to the Edge Function for each calendar event.
buildCalendarEventsFromSchedule
Converts a parsed Schedule into an array of CalendarEventInput objects ready for the Edge Function.
Parameters
Parameters
The full parsed schedule object. Its
sessions array is iterated to produce events. See the Schedule type below.The first day of the academic semester. Used to compute the first occurrence of each weekday class via
getFirstDateOfDay.The last day of the academic semester. Converted to
YYYYMMDDTHHMMSSZ format and used as the UNTIL value in each RRULE.An IANA timezone string (e.g.
"America/Guayaquil"). Defaults to the device’s local timezone via Intl.DateTimeFormat().resolvedOptions().timeZone.Sessions that are skipped
Sessions that are skipped
A session is excluded from the output if any of the following are true:
session.conflict === true— the session has a scheduling conflictsession.isVirtual === true— the session has no physical time slotsession.dayisundefinedor emptysession.startTimeorsession.endTimeisundefinedor empty- The computed first occurrence date falls after
semesterEnd
RRULE format
RRULE format
Each event carries a single recurrence rule with the format:The
UNTIL timestamp is derived from semesterEnd with its time set to 23:59:59 and serialized to UTC Z format. There is no BYDAY constraint in the Edge path (the start date already pins the correct weekday); the useGoogleCalendar hook path (googleAuth.ts) additionally appends a per-session BYDAY value (e.g. BYDAY=MO) to each event’s RRULE.syncCalendarEvents
Sends the built events to the google-calendar-sync Edge Function and returns the sync result.
Parameters
Parameters
Return type — SyncCalendarResponse
Return type — SyncCalendarResponse
true if all events were created without error.A human-readable status message, e.g.
"Se crearon 18 evento(s) en Google Calendar.".An array of the created Google Calendar event objects, each containing the event’s
id and an optional direct htmlLink.Early-exit conditions
Early-exit conditions
The function returns immediately with
{ success: false, ... } in the following cases (no Edge Function call is made):- Supabase is not configured (
isSupabaseConfigured()returnsfalse) eventsarray is empty
Edge Function: google-calendar-sync
The Edge Function is deployed at supabase/functions/google-calendar-sync/index.ts and runs on Deno. It requires the following Supabase secrets to be set:
Token Refresh Logic
The function checks whether the storedaccess_token needs refreshing before making any Google API calls:
needsRefresh returns true, a refresh_token grant is sent to https://oauth2.googleapis.com/token. The new access_token and updated expiry_date are written back to user_calendar_tokens before any events are inserted.
Per-Event Retry on 401 / 403
If inserting a single event returnsHTTP 401 or HTTP 403, the Edge Function performs a second token refresh inline and retries that event once. This handles the edge case where a token expires mid-batch.
Request / Response shape
useGoogleCalendar Hook
The useGoogleCalendar hook (googleAuth.ts) provides the browser-side Google Calendar integration path using the Google API JavaScript Library (GAPI) and the Google Identity Services (GIS) SDK. It loads both scripts dynamically, initializes an OAuth2 token client, and exposes syncScheduleToCalendar — which creates a new named Google Calendar and batch-inserts all class sessions directly from the browser without going through the Edge Function.
Return values
Return values
true while the GAPI and GIS scripts are loading or while initialization is in progress.true when window.gapi.client.getToken() returns a valid access token.Any error message from initialization or token request.
Loads the GAPI and GIS scripts, initializes the GAPI client with the Calendar discovery doc, and creates the OAuth2 token client. Called automatically on mount; safe to call multiple times (deduplicated via a promise ref).
Requests an OAuth2 access token (prompting for consent on first use), creates a new Google Calendar named
Horario UTM – {academic_period}, then batch-inserts all non-virtual, non-conflicting sessions as weekly recurring events. Returns { success: boolean; message: string }.RRULE format in this path
RRULE format in this path
Unlike the Edge Function path, Spanish day names are mapped to RRULE tokens via an inline
useGoogleCalendar appends a per-session BYDAY token to each recurrence rule so that each event is explicitly anchored to its day of the week:dayRuleMap:| Spanish | BYDAY |
|---|---|
| Lunes | MO |
| Martes | TU |
| Miércoles | WE |
| Jueves | TH |
| Viernes | FR |
Required environment variable
Required environment variable
The hook reads
GOOGLE_CLIENT_ID from the constants module (populated from VITE_GOOGLE_CLIENT_ID). If the constant is empty, initializeGoogleApi throws immediately with a descriptive error message.useCalendarStatus Hook
The useCalendarStatus hook manages the link state between the current user and their Google Calendar tokens. It is used by CalendarModal to gate the Sync button.
Return values
Return values
true when a row exists in user_calendar_tokens for the authenticated user.true while the hook is checking the database.Any error message surfaced from the database query or auth call.
Upserts a
CalendarTokens object into user_calendar_tokens for the current user. Preserves an existing refresh_token when the new token response does not include one (Google only returns a refresh token on first authorization).Re-queries
user_calendar_tokens to update isLinked. Called automatically on mount and whenever CalendarModal opens.CalendarTokens type
CalendarTokens type
Relevant Types
Database Tables
user_calendar_tokens
Stores
access_token, refresh_token, and expiry_date per user. The Edge Function reads from and writes back to this table.profiles
Stores user display name, avatar, and career. Queried to personalize the dashboard but not involved in the sync flow.
schedules
Persists the parsed timetable. The
sessions column is the source array iterated by buildCalendarEventsFromSchedule.