-
Notifications
You must be signed in to change notification settings - Fork 2
Achen 237 google calendar permission request #262
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?
Changes from all commits
5a39e31
0d9fce6
cea9707
d6be077
a1c496d
f045efc
0c9c647
c89e9e5
59523d4
0269c09
05b4392
de38786
1ac3d1c
691caa5
8f1bb3a
0c26c95
577c480
0740076
46ecee9
7ec77e2
f6310c2
185e9f9
4638924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import type { OAuth2Tokens } from "arctic"; | ||
| import { decodeIdToken } from "arctic"; | ||
| import { and, eq } from "drizzle-orm"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { cookies } from "next/headers"; | ||
| import { db } from "@/db"; | ||
| import { oauthAccounts, users } from "@/db/schema"; | ||
| import { oauthAccounts } from "@/db/schema"; | ||
| import { setSessionTokenCookie } from "@/lib/auth/cookies"; | ||
| import { oauth } from "@/lib/auth/oauth"; | ||
| import { createSession, generateSessionToken } from "@/lib/auth/session"; | ||
|
|
@@ -22,9 +22,8 @@ export async function GET(request: Request): Promise<Response> { | |
| const codeVerifier = cookieStore.get("oauth_code_verifier")?.value ?? null; | ||
| const redirectUrl = cookieStore.get("auth_redirect_url")?.value ?? "/"; | ||
|
|
||
| cookieStore.delete("auth_redirect_url"); | ||
| cookieStore.delete("oauth_state"); | ||
| cookieStore.delete("oauth_code_verifier"); | ||
| cookieStore.delete("session"); | ||
| cookieStore.delete({ name: "session", path: "/" }); | ||
|
|
||
| if ( | ||
| code === null || | ||
|
|
@@ -127,7 +126,16 @@ export async function GET(request: Request): Promise<Response> { | |
| oauthRefreshToken: googleRefreshToken, | ||
| oauthAccessTokenExpiresAt: googleTokenExpiry, | ||
| }); | ||
|
|
||
| cookieStore.delete("session"); | ||
| cookieStore.delete({ name: "session", path: "/" }); | ||
|
|
||
| await setSessionTokenCookie(sessionToken, session.expiresAt); | ||
|
|
||
| cookieStore.delete("oauth_state"); | ||
| cookieStore.delete("oauth_code_verifier"); | ||
| cookieStore.delete("auth_redirect_url"); | ||
|
Comment on lines
+135
to
+137
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: why are we only deleting these inside of this code path, instead of always?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, the cookies should also be deleted for the new user branch. I added the same deletions into that branch |
||
|
|
||
| const userRecord = await getUserById(existingUser.id); | ||
|
|
||
| if (!userRecord) { | ||
|
|
@@ -145,6 +153,9 @@ export async function GET(request: Request): Promise<Response> { | |
| oauthRefreshToken: googleRefreshToken, | ||
| oauthAccessTokenExpiresAt: googleTokenExpiry, | ||
| }); | ||
|
|
||
| // cookieStore.delete("session"); | ||
| // cookieStore.delete({ name: "session", path: "/" }); | ||
|
aizilerts marked this conversation as resolved.
|
||
| await setSessionTokenCookie(sessionToken, session.expiresAt); | ||
|
|
||
| memberId = user.memberId; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import { fetchGoogleCalendarEvents } from "@actions/availability/google/calendar/action"; | ||
| import { useDrag } from "@use-gesture/react"; | ||
| import { formatInTimeZone } from "date-fns-tz"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { useCallback, useEffect, useMemo, useState } from "react"; | ||
| import { useShallow } from "zustand/shallow"; | ||
| import { | ||
|
|
@@ -133,10 +134,15 @@ export function Availability({ | |
| user: UserProfile | null; | ||
| scheduledBlocks: SelectScheduledMeeting[]; | ||
| }) { | ||
| const router = useRouter(); | ||
| const availabilityView = useAvailabilityViewStore( | ||
| (state) => state.availabilityView, | ||
| ); | ||
|
|
||
| const overlayGoogleCalendar = useAvailabilityViewStore( | ||
| (state) => state.overlayGoogleCalendar, | ||
| ); | ||
|
|
||
| const selectionIsLocked = useGroupSelectionStore( | ||
| (state) => state.selectionIsLocked, | ||
| ); | ||
|
|
@@ -218,6 +224,7 @@ export function Availability({ | |
| const [googleCalendarEvents, setGoogleCalendarEvents] = useState< | ||
| GoogleCalendarEvent[] | ||
| >([]); | ||
| // const [hasFetchedCalendar, setHasFetchedCalendar] = useState(false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment |
||
|
|
||
| const [availabilityDates, setAvailabilityDates] = useState(() => | ||
| deriveInitialAvailability({ | ||
|
|
@@ -280,27 +287,39 @@ export function Availability({ | |
| }, [confirmSave]); | ||
|
|
||
| useEffect(() => { | ||
| if (availabilityDates.length > 0 && anchorNormalizedDate.length > 0) { | ||
| const firstDateISO = anchorNormalizedDate[0].toISOString(); | ||
|
|
||
| const lastDateObj = new Date( | ||
| anchorNormalizedDate[anchorNormalizedDate.length - 1], | ||
| ); | ||
| lastDateObj.setHours(23, 59, 59, 999); | ||
| const lastDateISO = lastDateObj.toISOString(); | ||
|
|
||
| fetchGoogleCalendarEvents(firstDateISO, lastDateISO) | ||
| .then((events) => { | ||
| setGoogleCalendarEvents(events); | ||
| }) | ||
| .catch((error) => { | ||
| console.error("Error fetching Google Calendar events:", error); | ||
| setGoogleCalendarEvents([]); | ||
| }); | ||
| } else { | ||
| setGoogleCalendarEvents([]); | ||
| if (!overlayGoogleCalendar) { | ||
| return; | ||
| } | ||
| }, [availabilityDates, anchorNormalizedDate]); | ||
|
|
||
| if (availabilityDates.length === 0 || anchorNormalizedDate.length === 0) | ||
| return; | ||
|
|
||
| const firstDateISO = anchorNormalizedDate[0].toISOString(); | ||
| const lastDateObj = new Date( | ||
| anchorNormalizedDate[anchorNormalizedDate.length - 1], | ||
| ); | ||
| lastDateObj.setHours(23, 59, 59, 999); | ||
|
|
||
| fetchGoogleCalendarEvents(firstDateISO, lastDateObj.toISOString()).then( | ||
| (result) => { | ||
| if ( | ||
| result.status === "missing_scope" || | ||
| result.status === "not_authenticated" | ||
| ) { | ||
| router.push("/auth/login/google/?prompt=consent"); | ||
|
|
||
| return; | ||
| } | ||
| setGoogleCalendarEvents(result.events); | ||
| }, | ||
| ); | ||
| }, [ | ||
| overlayGoogleCalendar, | ||
| availabilityDates, | ||
| anchorNormalizedDate, | ||
| // hasFetchedCalendar, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit |
||
| router, | ||
| ]); | ||
|
|
||
| const members = useMemo(() => { | ||
| const presentMemberIds = [ | ||
|
|
@@ -658,6 +677,7 @@ export function Availability({ | |
| currentPageAvailability={currentPageAvailability} | ||
| googleCalendarEvents={googleCalendarEvents} | ||
| meetingDates={meetingData.dates} | ||
| showGoogleCalendar={overlayGoogleCalendar} | ||
| /> | ||
| )} | ||
| </tr> | ||
|
|
@@ -685,7 +705,6 @@ export function Availability({ | |
| availabilityDates={availabilityDates} | ||
| fromTime={fromTimeMinutes} | ||
| members={members} | ||
| timezone={userTimezone} | ||
| anchorNormalizedDate={anchorNormalizedDate} | ||
| currentPageAvailability={currentPageAvailability} | ||
| availabilityTimeBlocks={availabilityTimeBlocks} | ||
|
|
||
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.
issue: why are we deleting the same cookies twice?
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.
Originally I had both of these just to make sure the cookies were being deleted, as I was having issues with that. I looked at the session token cookie function again and I believe we only need the second one, so I deleted the first