Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/evently.client/src/lib/services/auth-service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { redirect } from "@tanstack/react-router";
import axios from "axios";
import { Account } from "~/lib/domains/entities";

Expand All @@ -23,3 +24,21 @@ export async function getAccount(): Promise<Account | null> {
}
return null;
}

/**
* Validate against the user's `Account` in the route context.
* Redirect to login page if authentication fails.
* Tightly coupled with TanStack framework
* @param account
*/
export async function guardRoute(account: Account | null): Promise<void> {
if (account == null) {
throw redirect({
to: "/login",
replace: true,
search: {
redirect: location.href
}
});
}
}
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location.href usage will fail in server-side rendering contexts. Consider using the route context or a safer alternative to get the current URL.

Copilot uses AI. Check for mistakes.
256 changes: 136 additions & 120 deletions src/evently.client/src/routeTree.gen.ts

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions src/evently.client/src/routes/(auth)/gatherings/route.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";

export const Route = createFileRoute("/(auth)/bookings")({
export const Route = createFileRoute("/_auth")({
beforeLoad: ({ context }) => {
if (context.account == null) {
throw redirect({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Card, Tabs, TabState } from "~/lib/components";
import cloneDeep from "lodash.clonedeep";
import { useQuery } from "@tanstack/react-query";

export const Route = createFileRoute("/(auth)/bookings/attending/")({
export const Route = createFileRoute("/bookings/(auth)/attending/")({
loader: ({ context }) => ({ account: context.account }),
component: GetBookingsPage,
pendingComponent: () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BookingsTable, Jumbotron, StatsCard } from "./-components";
import { useInterval } from "usehooks-ts";
import type { PageResult } from "~/lib/domains/interfaces";

export const Route = createFileRoute("/(auth)/bookings/hosting/$gatheringId/dashboard/")({
export const Route = createFileRoute("/bookings/(auth)/hosting/$gatheringId/dashboard/")({
loader: async ({ params }) => {
const gatheringId: number = parseInt(params.gatheringId);
const gathering: Gathering = (await getGathering(gatheringId)) ?? new Gathering();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ToastContent, ToastStatus, toastStyles } from "~/lib/domains/models";
import { useForm } from "@tanstack/react-form";
import { FieldErrMsg as FieldInfo } from "~/lib/components";

export const Route = createFileRoute("/(auth)/bookings/hosting/$gatheringId/dashboard/scan")({
export const Route = createFileRoute("/bookings/(auth)/hosting/$gatheringId/dashboard/scan")({
component: RouteComponent
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Card, Tabs, TabState } from "~/lib/components";
import { useQuery } from "@tanstack/react-query";
import cloneDeep from "lodash.clonedeep";

export const Route = createFileRoute("/(auth)/bookings/hosting/")({
export const Route = createFileRoute("/bookings/(auth)/hosting/")({
component: GetHostedGatheringsPage,
pendingComponent: () => (
<div className="h-full">
Expand Down
15 changes: 15 additions & 0 deletions src/evently.client/src/routes/bookings/(auth)/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createFileRoute, Outlet } from "@tanstack/react-router";
import { guardRoute } from "~/lib/services";

export const Route = createFileRoute("/bookings/(auth)")({
beforeLoad: ({ context }) => guardRoute(context.account),
component: AuthLayout
});

function AuthLayout() {
return (
<>
<Outlet />
</>
);
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The React Fragment wrapper is unnecessary here. You can return <Outlet /> directly.

Suggested change
return (
<>
<Outlet />
</>
);
return <Outlet />;

Copilot uses AI. Check for mistakes.
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { fetchFile, getCategories, getGathering, sleep, updateGathering } from "
import {
useGatheringForm,
type GatheringForm as IGatheringForm
} from "~/routes/(auth)/gatherings/-services";
} from "~/routes/gatherings/-services";
import { GatheringReqDto, ToastContent } from "~/lib/domains/models";
import { GatheringForm } from "~/routes/(auth)/gatherings/-components";
import { GatheringForm } from "~/routes/gatherings/-components";

export const Route = createFileRoute("/(auth)/gatherings/$gatheringId/update")({
export const Route = createFileRoute("/gatherings/$gatheringId/(auth)/update")({
loader: async ({ params }) => {
const gatheringId: number = parseInt(params.gatheringId);
let gathering: Gathering | null = await getGathering(gatheringId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useState, type JSX } from "react";
import { createGathering, getCategories, sleep } from "~/lib/services";
import { useGatheringForm, type GatheringForm as IGatheringForm } from "./-services";
import { GatheringReqDto, ToastContent } from "~/lib/domains/models";
import { GatheringForm } from "~/routes/(auth)/gatherings/-components";
import { GatheringForm } from "~/routes/gatherings/-components";

export const Route = createFileRoute("/(auth)/gatherings/create")({
export const Route = createFileRoute("/gatherings/(auth)/create")({
loader: async () => {
const categories: Category[] = await getCategories();
return { categories };
Expand Down
15 changes: 15 additions & 0 deletions src/evently.client/src/routes/gatherings/(auth).route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createFileRoute, Outlet } from "@tanstack/react-router";
import { guardRoute } from "~/lib/services";

export const Route = createFileRoute("/gatherings/(auth)")({
beforeLoad: ({ context }) => guardRoute(context.account),
component: AuthLayout
});

function AuthLayout() {
return (
<>
<Outlet />
</>
);
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The React Fragment wrapper is unnecessary here. You can return <Outlet /> directly.

Suggested change
return (
<>
<Outlet />
</>
);
return <Outlet />;

Copilot uses AI. Check for mistakes.
}