Skip to content

Commit

Permalink
admin and doctor page auth url issue solved
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 11, 2024
1 parent ed94faf commit 5e902e4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const metadata: Metadata = {
};

const AdminLayoutWrapper: FC<AdminLayoutWrapperProps> = ({ children, signin }) => {
return <Layout signin={signin}>{children}</Layout>;
return <Layout auth={signin}>{children}</Layout>;
};

export default AdminLayoutWrapper;
19 changes: 13 additions & 6 deletions client/components/layout/AdminLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@ import AdminLayoutWithSideBar from "@/components/layout/AdminLayoutWithSideBar";
import UniversalSkelton from "@/components/skeletons/Universal";
import { AdminSideBarLinks } from "@/constants";
import { useAuth } from "@/lib/hooks/useAuth";
import { usePathname, useRouter } from "next/navigation";
import { ReactNode, useEffect, useState } from "react";

type Props = {
children: ReactNode;
signin: ReactNode;
auth: ReactNode;
};

const Layout = ({ children, signin }: Props) => {
const Layout = ({ children, auth }: Props) => {
const { adminToken } = useAuth();
const [isLoading, setLoading] = useState(true);

const router = useRouter();
const path = usePathname();
useEffect(() => {
if (adminToken && path.includes('/otp-verification')) {
router.replace('/doctor');
}
}, [adminToken, path, router]);
useEffect(() => {
const timer = setTimeout(() => {
setLoading(false);
}, 0);
return () => clearTimeout(timer);
});

}, []);
if (isLoading) {
return <UniversalSkelton />;
}
Expand All @@ -32,7 +39,7 @@ const Layout = ({ children, signin }: Props) => {
<main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-6">{children}</main>
</AdminLayoutWithSideBar>
) : (
signin
auth
)}
</>
);
Expand Down
13 changes: 10 additions & 3 deletions client/components/layout/DoctorLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DoctorLayoutWithSideBar from "@/components/layout/DoctorLayoutWithSideBar
import UniversalSkelton from "@/components/skeletons/Universal";
import { DoctorsSidebarLinks } from "@/constants";
import { useAuth } from "@/lib/hooks/useAuth";
import { usePathname, useRouter } from "next/navigation";
import { ReactNode, useEffect, useState } from "react";

type Props = {
Expand All @@ -11,15 +12,21 @@ type Props = {
};

const Layout = ({ children, auth }: Props) => {
const { doctorToken, setCredentials, otpMailDoctor } = useAuth();
const { doctorToken } = useAuth();
const [isLoading, setLoading] = useState(true);

const path = usePathname();
const router = useRouter()
useEffect(() => {
if (doctorToken && (path.includes('/otp-verification') || path.includes('/signup') || path.includes('/reset-password'))) {
router.replace('/doctor');
}
}, [doctorToken, path, router]);
useEffect(() => {
const timer = setTimeout(() => {
setLoading(false);
}, 0);
return () => clearTimeout(timer);
});
}, []);

if (isLoading) {
return <UniversalSkelton />;
Expand Down
3 changes: 0 additions & 3 deletions server/src/presentation/middlewares/AdminAuthMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export default class AdminAuthMiddleware {
}
req.admin = { email, id };

console.log(role);


next();
} catch (error: any) {
if (error.message === "Token Expired") {
Expand Down

1 comment on commit 5e902e4

@vercel
Copy link

@vercel vercel bot commented on 5e902e4 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.