I am making a project using Next js version 14.1.1, in that after the user is authenticated, they are to be redirected to localhost:3000/onboarding, but they are not being redirected, even if I type it manually, it redirects me to home page, what is the issue, not able to figure out
here is the code of app/[locale]/onboarding/page.tsx
import { OnboardingFormProvider } from "@/context/OnboardingForm";
import { checkIfUserCompletedOnboarding } from "@/lib/checkIfUserCompletedOnboarding";
const Onboarding = async () => {
const session = await checkIfUserCompletedOnboarding("/onboarding");
console.log(session);
return (
<OnboardingFormProvider session={session}>
<p>
Onboarding
</p>
</OnboardingFormProvider>
)
};
export default Onboarding;
here is the code of checkIfUserCompletedOnboarding
import { redirect } from "next-intl/server";
import { getAuthSession } from "./auth";
export const checkIfUserCompletedOnboarding = async (currentPath: string) => {
const session = await getAuthSession();
if (!session) redirect("/");
if (session.user.completedOnboarding && currentPath === "/onboarding")
redirect("/dashboard");
if (!session.user.completedOnboarding && currentPath !== "/onboarding") {
redirect("/onboarding?error=not-completed-onboarding");
}
return session;
};
after consoling it is returning what am I expecting, but it is not redirecting
here is the github link of my project – https://github.com/HemantRaj-2005/super-productive
I thought it was the problem of the version, earlier I was working with Next15, but I got a solution of downgrading the version, but even after that I am not able to figure it out
HEMANT RAJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
I’ve tried to run your code and tried login using email & password, it works.
No issues with the control flows in your code. Try to delete all installed packages and reinstall; import useRouter
from next/navigation
instead of next-intl/client
.
And remember to include [locale] in the url if you want to access manually by tying url on your browser. E.g. Should be localhost:3000/en/onboarding
or localhost:3000/te/onboarding
instead of localhost:3000/onboarding
4