-
-
Notifications
You must be signed in to change notification settings - Fork 190
Fix Google Calendar Auth Refresh #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Requesting review from @JeanMeijer who has experience with the following files modified in this PR:
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Tembo is working on fixing this failing workflow: |
| import { TRPCError } from "@trpc/server"; | ||
| import { eq } from "drizzle-orm"; | ||
|
|
||
| import { db } from "@repo/db"; | ||
| import { account } from "@repo/db/schema"; | ||
| import { env } from "@repo/env/server"; | ||
|
|
||
| interface GoogleTokenResponse { | ||
| access_token: string; | ||
| refresh_token?: string; | ||
| expires_in: number; | ||
| token_type: string; | ||
| } | ||
|
|
||
| interface MicrosoftTokenResponse { | ||
| access_token: string; | ||
| refresh_token?: string; | ||
| expires_in: number; | ||
| token_type: string; | ||
| } | ||
|
|
||
| interface RefreshTokenOptions { | ||
| refreshToken: string; | ||
| accountId: string; | ||
| } | ||
|
|
||
| export async function refreshGoogleAccessToken({ | ||
| refreshToken, | ||
| accountId, | ||
| }: RefreshTokenOptions): Promise<string> { | ||
| try { | ||
| const response = await fetch("https://oauth2.googleapis.com/token", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/x-www-form-urlencoded", | ||
| }, | ||
| body: new URLSearchParams({ | ||
| client_id: env.GOOGLE_CLIENT_ID, | ||
| client_secret: env.GOOGLE_CLIENT_SECRET, | ||
| refresh_token: refreshToken, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use better auth to refresh the tokens, instead of passing the accessToken to the provider pass enough info so we can refresh the token using better-auth
|
Thanks for the feedback about using Better Auth for token refreshing. I've refactored the token refresh implementation to leverage our auth service instead of directly managing OAuth tokens:
This approach is more secure and maintainable as the token refresh logic is now handled by the auth service rather than managed directly in our application. |
Description
Resolve Google Calendar authentication failures by implementing token refresh mechanism
Changes
refreshGoogleAccessTokenutility functionSummary by cubic
Automatically refreshes expired Google access tokens to stop calendar operations from failing, with a single retry after refresh and DB persistence of new tokens. Adds the same refresh flow for Microsoft Calendar.
Bug Fixes
Migration