Skip to content

Commit

Permalink
feat: add skelton + skip auth in localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
amjed-ali-k committed Oct 15, 2023
1 parent 2118d88 commit 0300694
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import {
Table,
TableBody,
Expand All @@ -49,6 +48,7 @@ import { mutate } from "swr";
import { ExamResultSingleApiType } from "@/app/api/secure/sbte-result/single/[resultId]/route";
import { convertToXlsx } from "@/app/lib/main";
import { writeFile } from "xlsx-js-style";
import { Skeleton } from "@/components/ui/skeleton";

const handleResultDownload = (id: string) => {
axios
Expand Down Expand Up @@ -197,7 +197,7 @@ export const columns: ColumnDef<ExamResultHistoryApiType[0]>[] = [
];

export function HistoryTable() {
const { data: apiData } = useGet<ExamResultHistoryApiType>(
const { data: apiData, isLoading } = useGet<ExamResultHistoryApiType>(
"/api/secure/sbte-result/history"
);

Expand Down Expand Up @@ -245,6 +245,13 @@ export function HistoryTable() {
))}
</TableHeader>
<TableBody>
{isLoading && (
<TableRow>
<TableCell colSpan={columns.length}>
<Skeleton className="w-full h-[20px]" />
</TableCell>
</TableRow>
)}
{table.getRowModel().rows?.length > 0 ? (
table.getRowModel().rows.map((row) => (
<TableRow
Expand Down
15 changes: 15 additions & 0 deletions src/components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { cn } from "@/lib/utils"

function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("animate-pulse rounded-md bg-primary/10", className)}
{...props}
/>
)
}

export { Skeleton }
6 changes: 6 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { NextResponse, NextRequest } from "next/server";
import { fetchUserId, getUserId } from "@/components/auth/server";

export async function middleware(req: NextRequest) {
// If localHost is true, we are running in development mode, so we can skip authentication
const localHost = req.headers.get("host")?.startsWith("localhost");
if (localHost) {
return NextResponse.next();
}

try {
const hanko = req.cookies.get("hanko")?.value;
if (!hanko) {
Expand Down

0 comments on commit 0300694

Please sign in to comment.