Let’s face it. You’re building an app, it needs Google Calendar integration, and you’re using Supabase. But wait—how do you even make Google sign-in work with calendar access? Don’t worry, we’ve got your back. In this guide, we’ll walk step-by-step through how to add Google Calendar authentication using Supabase and a dash of OAuth magic.
TLDR:
You can let users log in with Google and request access to their calendars all from your Supabase project. The trick is configuring the right OAuth scopes and redirect URIs. Supabase makes basic Google sign-ins easy, and we’ll show you how to level it up for Google Calendar. No backend coding wizardry needed!
🧠 Step 1: Set Up Google Developer Project
Before touching your Supabase dashboard, let’s get your Google app set up. Think of it like getting a VIP pass to Google Calendar.
- Go to Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to OAuth consent screen. Choose External if your app is public.
- Fill in the app name and add your email.
- Under Scopes, click “Add or Remove Scopes”.
- Search for:
../auth/calendar../calendar.events.readonly
- Save and continue through the rest of the wizard.
Now we need credentials!
- Go to Credentials.
- Click “Create Credentials” > OAuth Client ID.
- Choose Web Application as the type.
- Under Authorized Redirect URIs, add your Supabase redirect URI:
https://YourSupabaseProjectID.supabase.co/auth/v1/callback
Once it’s created, keep your Client ID and Client Secret handy. You’ll need them later 👇
🔌 Step 2: Add Google Auth to Supabase
Jump over to your Supabase dashboard now.
- Click on Authentication in the left side menu.
- Go to the Providers tab.
- Scroll down and find Google.
- Enter the Client ID and Client Secret from earlier.
- This is key: In the Scopes box, add:
https://www.googleapis.com/auth/calendar.readonly - Click Enable.
💡Tip: You can request more scopes based on what you need: edit events, manage calendars, or just snoop (politely) on availability.
🛠️ Step 3: Create the Login Flow
Now the fun stuff: Writing some frontend code to trigger Google login!
This is how you initiate login with Supabase and Google:
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://your-project-id.supabase.co', 'your-anon-key')
const signInWithGoogle = async () => {
await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
scopes: 'https://www.googleapis.com/auth/calendar.readonly',
redirectTo: window.location.origin,
}
})
}
When your user clicks your login button, this function handles the rest. Google brings them back after they choose their calendar permissions. Boom. They’re in! 🎉
🔐 Step 4: Get the Access Token
Once authenticated, Supabase stores the magic Google token you can use with Google APIs.
You can access it like this:
const session = supabase.auth.getSession()
const accessToken = session?.data?.session?.provider_token
Use this access token to make requests to Google Calendar!
const res = await fetch(
'https://www.googleapis.com/calendar/v3/users/me/calendarList',
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
)
const calendars = await res.json()
console.log(calendars)
Yup. That’s all it takes to list their calendars. 🗓️
😎 Step 5: Handle Logout
Don’t forget the logout button!
await supabase.auth.signOut()
This will sign your users out of your app. It won’t deauthorize their Google account, but it does make your app behave nicely.
🐛 Debugging Tips
- If you see a redirect URI mismatch, double-check the URI in Google Console matches Supabase exactly.
- If calendar scopes are not showing up, users might have denied access. Try logging in again with a fresh session.
- Test in Incognito mode to avoid login caching issues.
🎯 Wrapping it All Up
Congratulations! You just made your app 10x cooler with Google Calendar support. Your users can now sign in with their Google accounts and your app can fetch their calendar data like a boss.
To recap:
- Create a Google Cloud project and enable Calendar scopes.
- Connect Google as a provider in Supabase, including the right scopes.
- Trigger login with
signInWithOAuthand use the token to call Calendar APIs.
Your next mission (should you choose to accept it)? Write new calendar events, sync reminders, and show beautiful schedules. The API possibilities are endless.
Now go code something awesome. 🧑💻