aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/routes
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/routes')
-rw-r--r--frontend/app/routes/admin.dashboard.tsx9
-rw-r--r--frontend/app/routes/admin.games.tsx9
-rw-r--r--frontend/app/routes/admin.games_.$gameId.tsx16
-rw-r--r--frontend/app/routes/admin.users.tsx9
-rw-r--r--frontend/app/routes/dashboard.tsx6
-rw-r--r--frontend/app/routes/golf.$gameId.play.tsx6
-rw-r--r--frontend/app/routes/golf.$gameId.watch.tsx6
-rw-r--r--frontend/app/routes/login.tsx12
-rw-r--r--frontend/app/routes/logout.tsx4
9 files changed, 21 insertions, 56 deletions
diff --git a/frontend/app/routes/admin.dashboard.tsx b/frontend/app/routes/admin.dashboard.tsx
index ce3e910..4eb90b5 100644
--- a/frontend/app/routes/admin.dashboard.tsx
+++ b/frontend/app/routes/admin.dashboard.tsx
@@ -1,18 +1,13 @@
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { Link } from "@remix-run/react";
-import { isAuthenticated } from "../.server/auth";
+import { ensureAdminUserLoggedIn } from "../.server/auth";
export const meta: MetaFunction = () => {
return [{ title: "[Admin] Dashboard | iOSDC Japan 2024 Albatross.swift" }];
};
export async function loader({ request }: LoaderFunctionArgs) {
- const { user } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
- if (!user.is_admin) {
- throw new Error("Unauthorized");
- }
+ await ensureAdminUserLoggedIn(request);
return null;
}
diff --git a/frontend/app/routes/admin.games.tsx b/frontend/app/routes/admin.games.tsx
index af3554e..23e45c5 100644
--- a/frontend/app/routes/admin.games.tsx
+++ b/frontend/app/routes/admin.games.tsx
@@ -1,19 +1,14 @@
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { Link, useLoaderData } from "@remix-run/react";
import { adminApiGetGames } from "../.server/api/client";
-import { isAuthenticated } from "../.server/auth";
+import { ensureAdminUserLoggedIn } from "../.server/auth";
export const meta: MetaFunction = () => {
return [{ title: "[Admin] Games | iOSDC Japan 2024 Albatross.swift" }];
};
export async function loader({ request }: LoaderFunctionArgs) {
- const { user, token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
- if (!user.is_admin) {
- throw new Error("Unauthorized");
- }
+ const { token } = await ensureAdminUserLoggedIn(request);
const { games } = await adminApiGetGames(token);
return { games };
}
diff --git a/frontend/app/routes/admin.games_.$gameId.tsx b/frontend/app/routes/admin.games_.$gameId.tsx
index 34860ab..0d2cac6 100644
--- a/frontend/app/routes/admin.games_.$gameId.tsx
+++ b/frontend/app/routes/admin.games_.$gameId.tsx
@@ -5,7 +5,7 @@ import type {
} from "@remix-run/node";
import { Form, useLoaderData } from "@remix-run/react";
import { adminApiGetGame, adminApiPutGame } from "../.server/api/client";
-import { isAuthenticated } from "../.server/auth";
+import { ensureAdminUserLoggedIn } from "../.server/auth";
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return [
@@ -18,24 +18,14 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
};
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { user, token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
- if (!user.is_admin) {
- throw new Error("Unauthorized");
- }
+ const { token } = await ensureAdminUserLoggedIn(request);
const { gameId } = params;
const { game } = await adminApiGetGame(token, Number(gameId));
return { game };
}
export async function action({ request, params }: ActionFunctionArgs) {
- const { user, token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
- if (!user.is_admin) {
- throw new Error("Unauthorized");
- }
+ const { token } = await ensureAdminUserLoggedIn(request);
const { gameId } = params;
const formData = await request.formData();
diff --git a/frontend/app/routes/admin.users.tsx b/frontend/app/routes/admin.users.tsx
index 9eed263..219175e 100644
--- a/frontend/app/routes/admin.users.tsx
+++ b/frontend/app/routes/admin.users.tsx
@@ -1,19 +1,14 @@
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { adminApiGetUsers } from "../.server/api/client";
-import { isAuthenticated } from "../.server/auth";
+import { ensureAdminUserLoggedIn } from "../.server/auth";
export const meta: MetaFunction = () => {
return [{ title: "[Admin] Users | iOSDC Japan 2024 Albatross.swift" }];
};
export async function loader({ request }: LoaderFunctionArgs) {
- const { user, token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
- if (!user.is_admin) {
- throw new Error("Unauthorized");
- }
+ const { token } = await ensureAdminUserLoggedIn(request);
const { users } = await adminApiGetUsers(token);
return { users };
}
diff --git a/frontend/app/routes/dashboard.tsx b/frontend/app/routes/dashboard.tsx
index 1c2137d..45381e1 100644
--- a/frontend/app/routes/dashboard.tsx
+++ b/frontend/app/routes/dashboard.tsx
@@ -2,16 +2,14 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { Form, Link, useLoaderData } from "@remix-run/react";
import { apiGetGames } from "../.server/api/client";
-import { isAuthenticated } from "../.server/auth";
+import { ensureUserLoggedIn } from "../.server/auth";
export const meta: MetaFunction = () => {
return [{ title: "Dashboard | iOSDC Japan 2024 Albatross.swift" }];
};
export async function loader({ request }: LoaderFunctionArgs) {
- const { user, token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
+ const { user, token } = await ensureUserLoggedIn(request);
if (user.is_admin) {
return redirect("/admin/dashboard");
}
diff --git a/frontend/app/routes/golf.$gameId.play.tsx b/frontend/app/routes/golf.$gameId.play.tsx
index d498200..72f66bc 100644
--- a/frontend/app/routes/golf.$gameId.play.tsx
+++ b/frontend/app/routes/golf.$gameId.play.tsx
@@ -2,7 +2,7 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { ClientOnly } from "remix-utils/client-only";
import { apiGetGame, apiGetToken } from "../.server/api/client";
-import { isAuthenticated } from "../.server/auth";
+import { ensureUserLoggedIn } from "../.server/auth";
import GolfPlayApp from "../components/GolfPlayApp.client";
import GolfPlayAppConnecting from "../components/GolfPlayApps/GolfPlayAppConnecting";
@@ -17,9 +17,7 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
};
export async function loader({ params, request }: LoaderFunctionArgs) {
- const { token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
+ const { token } = await ensureUserLoggedIn(request);
const fetchGame = async () => {
return (await apiGetGame(token, Number(params.gameId))).game;
diff --git a/frontend/app/routes/golf.$gameId.watch.tsx b/frontend/app/routes/golf.$gameId.watch.tsx
index 0203e27..7c623e1 100644
--- a/frontend/app/routes/golf.$gameId.watch.tsx
+++ b/frontend/app/routes/golf.$gameId.watch.tsx
@@ -2,7 +2,7 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { ClientOnly } from "remix-utils/client-only";
import { apiGetGame, apiGetToken } from "../.server/api/client";
-import { isAuthenticated } from "../.server/auth";
+import { ensureUserLoggedIn } from "../.server/auth";
import GolfWatchApp from "../components/GolfWatchApp.client";
import GolfWatchAppConnecting from "../components/GolfWatchApps/GolfWatchAppConnecting";
@@ -17,9 +17,7 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
};
export async function loader({ params, request }: LoaderFunctionArgs) {
- const { token } = await isAuthenticated(request, {
- failureRedirect: "/login",
- });
+ const { token } = await ensureUserLoggedIn(request);
const fetchGame = async () => {
return (await apiGetGame(token, Number(params.gameId))).game;
diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx
index 95effaa..1c861fc 100644
--- a/frontend/app/routes/login.tsx
+++ b/frontend/app/routes/login.tsx
@@ -4,23 +4,19 @@ import type {
MetaFunction,
} from "@remix-run/node";
import { Form } from "@remix-run/react";
-import { authenticator } from "../.server/auth";
+import { ensureUserNotLoggedIn, login } from "../.server/auth";
export const meta: MetaFunction = () => {
return [{ title: "Login | iOSDC Japan 2024 Albatross.swift" }];
};
export async function loader({ request }: LoaderFunctionArgs) {
- return await authenticator.isAuthenticated(request, {
- successRedirect: "/dashboard",
- });
+ return await ensureUserNotLoggedIn(request);
}
export async function action({ request }: ActionFunctionArgs) {
- return await authenticator.authenticate("default", request, {
- successRedirect: "/dashboard",
- failureRedirect: "/login",
- });
+ await login(request);
+ return null;
}
export default function Login() {
diff --git a/frontend/app/routes/logout.tsx b/frontend/app/routes/logout.tsx
index 012d9e9..d697be2 100644
--- a/frontend/app/routes/logout.tsx
+++ b/frontend/app/routes/logout.tsx
@@ -1,7 +1,7 @@
import type { ActionFunctionArgs } from "@remix-run/node";
-import { authenticator } from "../.server/auth";
+import { logout } from "../.server/auth";
export async function action({ request }: ActionFunctionArgs) {
- await authenticator.logout(request, { redirectTo: "/" });
+ await logout(request);
return null;
}