when im on my protected route and i

when im on my protected route and i signout. the middleware would redirect me to auth page however the url will still say dashboard and things r rendered incorrectly like a bugged rewrite or smth
9 Replies
Sara
Sara5w ago
Show me your middleware.ts? And the sign out function you have
Sιɳɠυʅαɾ Sιɳɠυʅαɾιƚყ
function handleSignOut() {
try {
signOut()
toast.success("You have been signed out successfully")
} catch (_error) {
toast.error("Failed to sign out. Please try again.")
}
}
function handleSignOut() {
try {
signOut()
toast.success("You have been signed out successfully")
} catch (_error) {
toast.error("Failed to sign out. Please try again.")
}
}
export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
if (isSignInPage(request) && (await convexAuth.isAuthenticated())) {
return nextjsMiddlewareRedirect(request, "/dashboard");
}
if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
return nextjsMiddlewareRedirect(request, "/auth");
}
});
export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
if (isSignInPage(request) && (await convexAuth.isAuthenticated())) {
return nextjsMiddlewareRedirect(request, "/dashboard");
}
if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
return nextjsMiddlewareRedirect(request, "/auth");
}
});
Sara
Sara4w ago
I'm not seeing a problem here, but it happened with me alot because of the "replace state" in the redirect, should you worry about it? Not really
Sιɳɠυʅαɾ Sιɳɠυʅαɾιƚყ
I mean i should worry about it in my app cuz what happens breaks my layout render I have two separate routr groups, protected and public When i get redirected and url still says /dashboard It messss things up and some comps still render even tho they shouldn't Its like as if a client rewrite is happening and not a full server redirect Ai suggested i use router.replace on client after signout but that made things flash and kinda not instant and i would see 2 requests
Sara
Sara4w ago
Then force change it on your end, instead of returning a redirect from convrx, write your own
Sara
Sara4w ago
Changing the history? That might work but not really with the middle Yes.
Sιɳɠυʅαɾ Sιɳɠυʅαɾιƚყ
How would we do so?

Did you find this page helpful?