Skip to content

Commit

Permalink
fix: route redirecting on login
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Aug 8, 2023
1 parent 55798da commit 24d1d62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function Home() {
Profile
</Link>
</li>
<a href="/profile">Test</a>
</ul>
</nav>
</main>
Expand Down
11 changes: 5 additions & 6 deletions src/lib/auth/handle-sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ export const handleSignIn = async (
})
if (!res?.error) {
logger.debug("Sign in successful pushing to", callbackUrl)
//! Push with next/router doesn't work
//? When the user come from a basic route the click to a protected route and get
//? redirected here, the router.push doesn't work because the response is cached
//? and the user is infinitely redirected to the login page
// router.push(callbackUrl)
router.replace(callbackUrl)
router.push(callbackUrl)
//? Refreshing the router is necessary due to next.js client cache, see: https://nextjs.org/docs/app/building-your-application/caching
router.refresh()
resolve(true)
} else {
console.error(res.error)
Expand Down Expand Up @@ -127,6 +124,8 @@ export const handleSignUp = async ({
} else {
logger.debug("Pushing to profile page")
router.push("/profile")
//? Refreshing the router is necessary due to next.js client cache, see: https://nextjs.org/docs/app/building-your-application/caching
router.refresh()
resolve(true)
}
}
Expand Down

0 comments on commit 24d1d62

Please sign in to comment.