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

306
Views
Next.js redirect to login page and redirect back

I need to redirect our users to a SSO form that is handle by another team. This form (is not a next.js app) is on the same domain as the next.js app. I try to follow https://nextjs.org/docs/authentication#authenticating-server-rendered-pages but I can't figure out on how to get the current URL, so I can tell the SSO to redirect back once authentication is finish.

return {
  redirect: {
    destination: `/sso/form?redirect=${currentUrl}`,
    permanent: false,
  },
}

Any idea, on how to get the currentUrl?

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

0

The context contain a property called resolvedUrl corresponding to the current route.

        const { resolvedUrl, req } = context;
        const baseUrl = getBaseUrl(req);
        const currentUrl = `${baseUrl}${resolvedUrl}`;

getBaseUrl is an helper function that return the base url of our current nextjs app.

about 4 years ago · Juan Pablo Isaza Report

0

The redirection you are doing on the getServerSideProps is done in the server so no dom info can be accessed on that level. You have tu pass the path info to the server in a cookie or something like that.

Anyway, if im not mistaken, you redirect to SSO when you try to load a page and the auth fails. This auth happens on getServerSideProps so you can hardcode the SSO redirection url because you call a different getServerSideProps everytime you go to a new page.

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!