diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-31 01:49:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-31 01:49:34 +0900 |
| commit | 7a06def8085b432994dc054037183795e7ec25a0 (patch) | |
| tree | 95456a82897787bac87c350dbc65cad6f35e4ebd /frontend/app/routes/admin.users.tsx | |
| parent | 19a75493f5897685cb36c66c7bb3d31ea6a6bd2d (diff) | |
| parent | 5bcffc6a83021b2bcb06b8c6f622a1d623fc753e (diff) | |
| download | iosdc-japan-2024-albatross-7a06def8085b432994dc054037183795e7ec25a0.tar.gz iosdc-japan-2024-albatross-7a06def8085b432994dc054037183795e7ec25a0.tar.zst iosdc-japan-2024-albatross-7a06def8085b432994dc054037183795e7ec25a0.zip | |
Merge branch 'admin'
Diffstat (limited to 'frontend/app/routes/admin.users.tsx')
| -rw-r--r-- | frontend/app/routes/admin.users.tsx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/frontend/app/routes/admin.users.tsx b/frontend/app/routes/admin.users.tsx new file mode 100644 index 0000000..d9901a2 --- /dev/null +++ b/frontend/app/routes/admin.users.tsx @@ -0,0 +1,48 @@ +import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; +import { useLoaderData } from "@remix-run/react"; +import { isAuthenticated } from "../.server/auth"; +import { apiClient } from "../.server/api/client"; + +export const meta: MetaFunction = () => { + return [{ title: "[Admin] Users | iOSDC 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 { data, error } = await apiClient.GET("/admin/users", { + params: { + header: { + Authorization: `Bearer ${token}`, + }, + }, + }); + if (error) { + throw new Error(error.message); + } + return { users: data.users }; +} + +export default function AdminUsers() { + const { users } = useLoaderData<typeof loader>()!; + + return ( + <div> + <div> + <h1>[Admin] Users</h1> + <ul> + {users.map((user) => ( + <li key={user.user_id}> + {user.display_name} (uid={user.user_id} username={user.username}) + {user.is_admin && <span> admin</span>} + </li> + ))} + </ul> + </div> + </div> + ); +} |
