Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm with auth SSR #2895

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions web/components/layout/auth/authLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @next/next/no-img-element */

import { useRouter } from "next/router";
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useAlertBanners, useChangelog } from "../../../services/hooks/admin";
import UpgradeProModal from "../../shared/upgradeProModal";
import { Row } from "../common";
Expand All @@ -12,6 +12,7 @@ import DemoModal from "./DemoModal";
import MainContent from "./MainContent";
import Sidebar from "./Sidebar";
import { ErrorBoundary } from "@/components/ui/error-boundary";
import { useUser } from "@supabase/auth-helpers-react";

interface AuthLayoutProps {
children: React.ReactNode;
Expand All @@ -22,9 +23,9 @@ const AuthLayout = (props: AuthLayoutProps) => {
const router = useRouter();
const { pathname } = router;
const org = useOrg();
const user = useUser();

const [open, setOpen] = useState(false);
const [showTermsModal, setShowTermsModal] = useState(false);

const currentPage = useMemo(() => {
const path = pathname.split("/")[1];
Expand All @@ -40,6 +41,16 @@ const AuthLayout = (props: AuthLayoutProps) => {

const { changelog, isLoading: isChangelogLoading } = useChangelog();

useEffect(() => {
if (!user) {
router.push("/signin?unauthorized=true");
}
}, [router, user]);

if (!user) {
return null;
}

return (
<MetaData
title={`${currentPage} ${
Expand Down
9 changes: 8 additions & 1 deletion web/components/templates/requestsV2/requestsPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,14 @@ const RequestsPageV2 = (props: RequestsPageV2Props) => {
isLive ? "text-green-500 animate-pulse" : "text-slate-500"
)}
size="sm_sleek"
onClick={() => setIsLive(!isLive)}
onClick={() => {
if (!isLive) {
searchParams.delete("t");
setIsLive(true);
} else {
setIsLive(false);
}
}}
>
<div
className={clsx(
Expand Down
18 changes: 1 addition & 17 deletions web/pages/properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import PropertiesPage from "../components/templates/properties/propertiesPage";
import { withAuthSSR } from "../lib/api/handlerWrappers";
import { ReactElement } from "react";

interface PropertiesProps {
user: User;
}
interface PropertiesProps {}

const Properties = (props: PropertiesProps) => {
const { user } = props;

return <PropertiesPage />;
};

Expand All @@ -19,15 +15,3 @@ Properties.getLayout = function getLayout(page: ReactElement) {
};

export default Properties;

export const getServerSideProps = withAuthSSR(async (options) => {
const {
userData: { user },
} = options;

return {
props: {
user,
},
};
});
13 changes: 8 additions & 5 deletions web/pages/sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { User } from "@supabase/auth-helpers-react";
import { SortDirection } from "../services/lib/sorts/requests/sorts";
import { ReactElement } from "react";
import SessionsPage from "../components/templates/sessions/sessionsPage";
import { GetServerSideProps, GetServerSidePropsContext } from "next";
import { ParsedUrlQuery } from "querystring";

interface SessionsProps {
user: User;
currentPage: number;
pageSize: number;
sort: {
Expand Down Expand Up @@ -37,16 +38,18 @@ Sessions.getLayout = function getLayout(page: ReactElement) {

export default Sessions;

export const getServerSideProps = withAuthSSR(async (options) => {
export const getServerSideProps: GetServerSideProps<
SessionsProps,
ParsedUrlQuery
> = async (context: GetServerSidePropsContext) => {
const { page, page_size, sortKey, sortDirection, isCustomProperty, tab } =
options.context.query;
context.query;

const currentPage = parseInt(page as string, 10) || 1;
const pageSize = parseInt(page_size as string, 10) || 10;

return {
props: {
user: options.userData.user,
currentPage,
pageSize,
sort: {
Expand All @@ -57,4 +60,4 @@ export const getServerSideProps = withAuthSSR(async (options) => {
defaultIndex: tab ? parseInt(tab as string) : 0,
},
};
});
};
20 changes: 1 addition & 19 deletions web/pages/users/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { User } from "@supabase/auth-helpers-nextjs";
import { GetServerSidePropsContext } from "next";

import { ReactElement } from "react";
Expand All @@ -8,7 +7,6 @@ import AuthLayout from "../../components/layout/auth/authLayout";
import { SupabaseServerWrapper } from "../../lib/wrappers/supabase";

interface UsersProps {
user: User;
page: number;
pageSize: number;
sort: {
Expand All @@ -19,7 +17,7 @@ interface UsersProps {
}

const Users = (props: UsersProps) => {
const { user, page, pageSize, sort } = props;
const { page, pageSize, sort } = props;

return <UsersPageV2 currentPage={page} pageSize={pageSize} sort={sort} />;
};
Expand All @@ -33,20 +31,6 @@ export default Users;
export const getServerSideProps = async (
context: GetServerSidePropsContext
) => {
const supabase = new SupabaseServerWrapper(context).getClient();

const {
data: { session },
} = await supabase.auth.getSession();

if (!session)
return {
redirect: {
destination: "/",
permanent: false,
},
};

const { page, page_size, sortKey, sortDirection, isCustomProperty } =
context.query;

Expand All @@ -55,8 +39,6 @@ export const getServerSideProps = async (

return {
props: {
initialSession: session,
user: session.user,
page: currentPage,
pageSize: pageSize,
sort: {
Expand Down
Loading