atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
962 stars 90 forks source link

Issue: user authentication and cookie management #197

Closed michaelprys closed 1 month ago

michaelprys commented 1 month ago

I'm having issues with user authentication:

  1. ready is always true. This property remains true even when the cookie is missing.
  2. loggedIn doesn't update in real-time. After logging in, I see the 'Error signing in' in the form and no redirect happens, because loggedIn is still false, even though the cookie was created. So the only solution is to refresh the page to see that I'm logged and redirect will apply. To show the 'sign out' instead of sign in I will also need loggedIn to be true.
  3. Cookie flag does not disappear. When I call the clear() method, it only sets the value in devtools Application to an empty string instead of completely removing it. I can still see 'nuxt-cookie' in the developer tools. Is it how it's supposed to work or is it a bug?

I would really appreciate the help with:

I'm looking for a possible solution.

atinux commented 1 month ago

how to update the UI immediately after logging in without needing a page refresh.

Just call useUserSession().fetch() to refresh the session on the frontend.

the differences between ready and loggedIn and which one to use to conditionally display elements like 'sign out' button? To me they seem like a same thing, but ready is for some reason always true.

Don't use ready as this is internal

how to properly handle cookie removal and its effect on the login state.

This is the behavior from H3 and it is fine to have an empty cookie as long as the session tells you that you are logged out

michaelprys commented 1 month ago

Thank you for the detailed answer! Works like a charm.