Skip to content

Commit

Permalink
Spring 2025
Browse files Browse the repository at this point in the history
  • Loading branch information
armintalaie committed Dec 18, 2024
1 parent a8e8320 commit ffa2e99
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 48 deletions.
7 changes: 6 additions & 1 deletion src/app/auth/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand Down
4 changes: 3 additions & 1 deletion src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 1 addition & 11 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -97,7 +87,7 @@ export default async function Home() {
<p className="gradient-subtitle text-center lg:text-left py-10">
{text.joinUsText}
</p>
<Link href="/portal/forms/241">
<Link href="/portal/forms/8">
<Button className="p-4" size={"xl"} icon>
<span className="text-lg">{text.joinUsButton}</span>
</Button>
Expand Down
1 change: 0 additions & 1 deletion src/app/portal/forms/[id]/apply/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default async function page({
/>
);
} catch (e) {
toast.error("Error loading application");
return redirect(`/portal/forms/${params.id}`);
}
}
64 changes: 32 additions & 32 deletions src/app/portal/forms/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
// 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: "[email protected]",
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({
Expand Down
2 changes: 1 addition & 1 deletion src/components/general/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function LandingPage() {
<p className="text-lg w-full text-center md:text-left gradient-subtitle">
{text.description}
</p>
<Link href="/portal/forms/241">
<Link href="/portal/forms/8">
<Button className="p-3 px-6" size={"xl"} icon>
<span className="text-lg">{text.joinUs}</span>
</Button>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ffa2e99

Please sign in to comment.