lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
MIT License
8.41k stars 449 forks source link

Check if user logged in on unprotected page when logging out to that page #1489

Closed moshetanzer closed 3 months ago

moshetanzer commented 3 months ago

Package

lucia

Describe the bug

For the login page of my Nuxt 3 app if user is logged in I want to redirect the user to dashboard page automatically. You can't use authenticatedUser() on the login page since it is not a protected page, and when using user to do a simple test like this both in middleware or on login page itself when signing out - it stays on dashboard page until complete refresh?

Thanks for the lib and goold luck with uni

//login.vue
const user = useUser();
if (user.value) {
  navigateTo("/dashboard");
}
pilcrowOnPaper commented 3 months ago

Sounds like a Nuxt question? I don't use Nuxt so I don't think I help much either

moshetanzer commented 3 months ago

@pilcrowOnPaper, nope - it is a lucia question. Why is user.value still true after logging out before completion of redirect to login page...

pilcrowOnPaper commented 3 months ago

Because there's nothing updating the value of user.value? Just set the value to null after making a fetch request if you need it before the redirect

moshetanzer commented 3 months ago

you rock - just to understand, after redirect it auto sets to null?

On Fri, Mar 15, 2024 at 1:20 AM pilcrow @.***> wrote:

Because there's nothing updating the value of user.value? Just set the value to null after making a fetch request if you need it before the redirect

— Reply to this email directly, view it on GitHub https://github.com/lucia-auth/lucia/issues/1489#issuecomment-1998633493, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATTEVLK6HMVCVXKH7OYH3Q3YYIWC7AVCNFSM6AAAAABEW7M7WWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJYGYZTGNBZGM . You are receiving this because you authored the thread.Message ID: @.***>

pilcrowOnPaper commented 3 months ago

When you redirect, the middleware for the destination page runs which fetches the latest user data