From ffa2e994b480c067c7f18d4cf5845240c2a8d57a Mon Sep 17 00:00:00 2001 From: Armin Talaie Date: Wed, 18 Dec 2024 00:32:09 -0800 Subject: [PATCH] Spring 2025 --- src/app/auth/actions.ts | 7 ++- src/app/auth/callback/route.ts | 4 +- src/app/page.tsx | 12 +---- src/app/portal/forms/[id]/apply/page.tsx | 1 - src/app/portal/forms/actions.ts | 64 ++++++++++++------------ src/components/general/hero.tsx | 2 +- src/lib/utils/supabase/middleware.ts | 4 +- 7 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/app/auth/actions.ts b/src/app/auth/actions.ts index e4e78381..c7738cb2 100644 --- a/src/app/auth/actions.ts +++ b/src/app/auth/actions.ts @@ -3,14 +3,19 @@ import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { createClient } from "@/lib/utils/supabase/server"; +import { headers, cookies } from "next/headers"; export async function login() { const supabase = createClient(); + const c = cookies(); + const redirectPath = `redirect=${c.get("x-path")?.value || ""}`; + c.delete("x-path"); + const callbackUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/auth/callback?${redirectPath}`; const { data, error } = await supabase.auth.signInWithOAuth({ provider: "google", options: { - redirectTo: process.env.NEXT_PUBLIC_BASE_URL + "/auth/callback", + redirectTo: callbackUrl, }, }); diff --git a/src/app/auth/callback/route.ts b/src/app/auth/callback/route.ts index a1409bcd..49c2a468 100644 --- a/src/app/auth/callback/route.ts +++ b/src/app/auth/callback/route.ts @@ -6,7 +6,9 @@ export async function GET(request: Request) { const { searchParams, origin } = new URL(request.url); const code = searchParams.get("code"); // if "next" is in param, use it as the redirect URL - const next = searchParams.get("next") ?? "/"; + const next = searchParams.get("redirect") ?? "/"; + + console.log("next", next); if (code) { const supabase = createClient(); diff --git a/src/app/page.tsx b/src/app/page.tsx index 0487e814..bee4c159 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -14,16 +14,6 @@ import MemberRoles from "@/components/general/memberRoles"; import ProjectSection from "@/components/general/projectSection"; import PartnerSection from "@/components/general/partnerSection"; -// const refreshProjects = async () => { -// const res = await fetch( -// `${process.env.NEXT_PUBLIC_BASE_URL}/api/projects/refresh` -// ); -// -// const data = await res.json(); -// console.log(data.data); -// return data.data; -// }; - const text = { aboutUsTitle: "What we do at", aboutUsSubtitle: "Launch Pad", @@ -97,7 +87,7 @@ export default async function Home() {

{text.joinUsText}

- + diff --git a/src/app/portal/forms/[id]/apply/page.tsx b/src/app/portal/forms/[id]/apply/page.tsx index 17672465..4f9bf54e 100644 --- a/src/app/portal/forms/[id]/apply/page.tsx +++ b/src/app/portal/forms/[id]/apply/page.tsx @@ -36,7 +36,6 @@ export default async function page({ /> ); } catch (e) { - toast.error("Error loading application"); return redirect(`/portal/forms/${params.id}`); } } diff --git a/src/app/portal/forms/actions.ts b/src/app/portal/forms/actions.ts index f235f798..3ca7dcc7 100644 --- a/src/app/portal/forms/actions.ts +++ b/src/app/portal/forms/actions.ts @@ -88,38 +88,38 @@ export async function submitApplication({ formId }: { formId: bigint }) { return newObj; } - // const updateSubmission = db.submissions.update({ - // where: { - // user_id_form_id: { - // form_id: formId, - // user_id: data.user.id, - // }, - // }, - // data: { - // status: "submitted", - // }, - // }); - - // const createApplication = db.applications.create({ - // data: { - // id: res.id!, - // status: null, - // reviewer_id: null, - // }, - // }); - - // await Promise.all([updateSubmission, createApplication]); - // const appEmail = res.details ? (res.details as Obj) : {}; - // const template = await render(SubmissionTemplate({ formTitle: form.title })); - // await sendEmail({ - // from: "no-reply@ubclaunchpad.com", - // fromName: "No-reply UBC Launch Pad", - // to: data.user.email!.toString(), - // subject: `${form.title} - Form Submitted`, - // html: template, - // cc: appEmail?.email as string, - // }); - // return true; + const updateSubmission = db.submissions.update({ + where: { + user_id_form_id: { + form_id: formId, + user_id: data.user.id, + }, + }, + data: { + status: "submitted", + }, + }); + + const createApplication = db.applications.create({ + data: { + id: res.id!, + status: null, + reviewer_id: null, + }, + }); + + await Promise.all([updateSubmission, createApplication]); + const appEmail = res.details ? (res.details as Obj) : {}; + const template = await render(SubmissionTemplate({ formTitle: form.title })); + await sendEmail({ + from: "no-reply@ubclaunchpad.com", + fromName: "No-reply UBC Launch Pad", + to: data.user.email!.toString(), + subject: `${form.title} - Form Submitted`, + html: template, + cc: appEmail?.email as string, + }); + return true; } export async function updateApplication({ diff --git a/src/components/general/hero.tsx b/src/components/general/hero.tsx index f627fc75..0e3ccec7 100644 --- a/src/components/general/hero.tsx +++ b/src/components/general/hero.tsx @@ -26,7 +26,7 @@ export default function LandingPage() {

{text.description}

- + diff --git a/src/lib/utils/supabase/middleware.ts b/src/lib/utils/supabase/middleware.ts index e83a0d27..f693ab49 100644 --- a/src/lib/utils/supabase/middleware.ts +++ b/src/lib/utils/supabase/middleware.ts @@ -53,7 +53,9 @@ export async function updateSession(request: NextRequest) { // no user, potentially respond by redirecting the user to the login page const url = request.nextUrl.clone(); url.pathname = "/auth"; - return NextResponse.redirect(url); + const resp = NextResponse.redirect(url); + resp.cookies.set("x-path", request.nextUrl.pathname); + return resp; } } catch (error) { console.error("Error fetching user", error);