Skip to content

Commit

Permalink
swr for session loading
Browse files Browse the repository at this point in the history
  • Loading branch information
radityaharya committed May 4, 2024
1 parent 1bfeff2 commit 7d1b4a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/app/workflow/Builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { toast } from "sonner";
import { useRouter } from "next/navigation";
import { LoadingWithText } from "~/components/LoadingSpinner";
import { useWorkflowData } from "~/hooks/useWorkflowData";
import useSWR from "swr";

function Builder({
params,
Expand All @@ -30,17 +31,18 @@ function Builder({
params: { id: string };
searchParams: any;
}) {
const { data: session } = useSession();
const { data: session, isLoading: sessionLoading } =
useSWR("/api/auth/session");

const flowId = params.id;

const router = useRouter();

useEffect(() => {
if (session) {
if (session?.user) {
setSessionStore(session);
}
}, [session]);
}
}, [session?.user]);

const {
rightBarSize,
Expand Down Expand Up @@ -178,7 +180,7 @@ function Builder({
</ResizablePanel>
<ResizableHandle withHandle />
<ResizablePanel defaultSize={83}>
{workflowIsLoading || sessionStore === null ? (
{workflowIsLoading || !session?.user ? (
<Loading />
) : (
<Flow />
Expand Down
2 changes: 1 addition & 1 deletion src/app/workflows/WorkflowGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export function WorkflowsGrid({ workflows }: WorkflowTableProps) {
(a, b) =>
new Date(b!.startedAt).getTime() - new Date(a!.startedAt).getTime(),
)
.slice(0, 500);
.slice(0, 4);

return (
<div className="pt-2 flex h-full flex-col-reverse xl:flex-row w-full gap-10">
Expand Down
18 changes: 9 additions & 9 deletions src/middlewares/handlers/userApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ export const withUserApi = (

const user = await getUser(request);

if (!user && pathname.startsWith("/workflow")) {
return NextResponse.redirect(
new URL("/auth/login", process.env.NEXTAUTH_URL),
);
}

if (!user) {
return errorResponse("Not authenticated", 401);
}
// if (!user && pathname.startsWith("/workflow")) {
// return NextResponse.redirect(
// new URL("/auth/login", process.env.NEXTAUTH_URL),
// );
// }

// if (!user) {
// return errorResponse("Not authenticated", 401);
// }

// user namespace check
if (pathname.startsWith("/api/user/")) {
Expand Down

0 comments on commit 7d1b4a1

Please sign in to comment.