Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
How to delay page transition in NextJs

I am trying to protect my private pages using HOC withAuth. Protection works fine but i dont want users to see loading for second while access token is being retrieved from local storage. And if i were to just return null after redirecting i get error that says received div without enclosing div (or something like that). Is there any way to delay route transition ? My HOC is

export function withAuth<T extends TWithAuth = TWithAuth>(
   WrappedComponent: React.ComponentType<T>,
   ): React.ComponentType<T> {
const InnerComponent = (props: T) => {
    const [loading, setLoading] = useState(true);
    const router = useRouter();
    useEffect(() => {
        const accessToken = TokenService.getAccessToken();

        if (!accessToken) {
            router.replace('/auth/login');
        } else {
            setLoading(false);
        }
    }, []);
    return loading ? <div>loading</div> : <WrappedComponent {...props} />;
};

InnerComponent.displayName = `withAuth(${WrappedComponent.displayName || WrappedComponent.name}`;

return InnerComponent;

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe you can use getServerSideProps on your private pages and wrap it inside your component that's handling the logic and would return a

{ redirect: { destination: "/auth/login" } }

if there is no accessToken

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!