How to go to the specific entered url
Answered
Muhammed Khal posted this in #help-forum
export default function DashboardLayout({ children }: RootLayoutProps) {
const { data: session } = useSession({
required: true,
});Auth Layoutexport default function AuthLayout({ children }: RootLayoutProps) {
const { data: session } = useSession();
const { profileId } = useProfileSwitchId();
const router = useRouter();
const pathname = usePathname();
const isFromAgency: any = session?.user?.profiles?.find(
(profile) => profile?.id === profileId
);
// Check for session.user and redirect to /dashboard
useEffect(() => {
if (isFromAgency?.agency ) {
router.push('/dashboard');
} else if (!isFromAgency?.agency) {
router.push('/client-dashboard');
}
}, [session, router, isFromAgency?.agency]);Guys that's my dashboard layout and login protected by the nextAuth
Here whatever the link I paste I mean like my hosting link plus the project id link it's goes to the login first but after that its goes to the dashboard instead of the entered url,
HOw can I achieve that like whatever the link I enter it should login then it should goes to that specific path
17 Replies
1. layouts should never be client components
2. you should do this in middleware
Answer
1. I can do that, I can make a new component and then make it as the server component
2. I'm not sure how can I do that, can you please help me
Any example or demo?
check the cookie next-auth sets
there are also middleware examples in their docs
Okay will check it thanks
Could you please send me the specific link of it
@Muhammed Khal Could you please send me the specific link of it
there is an entire area called nextjs
I mean for the 2nd one
thats what i am talking about
in the next auth docs
Okay
https://next-auth.js.org/configuration/options
Is that's the one?
Is that's the one?
the big option in the menu that says nextjs