Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useIsAuthenticated hook doesn't cause re-render #1541

Open
zarnocha opened this issue Jan 9, 2024 · 18 comments
Open

useIsAuthenticated hook doesn't cause re-render #1541

zarnocha opened this issue Jan 9, 2024 · 18 comments
Labels
enhancement New feature or request

Comments

@zarnocha
Copy link

zarnocha commented Jan 9, 2024

Hello.
As in the title the useIsAuthenticated hook won't cause component's re-render.

@wiktor-maruszewski
Copy link

I've got the same problem. Please fix it quickly! :(

@darkmatter18
Copy link
Member

Hey can you please elaborate what your intended behaviour is? I am sorry, but I can't understand

@imjulianeral
Copy link

I think I can explain. At least for my use case, when the auth state changes, my router redirects automatically without the need of an explicit redirect, why? because with useIsAuthenticated hook I can conditionally render what I need if the user is signed in or not, but since v3 this hook which is expected to trigger a rerender because it is a state handler which changes if the user is auth or not the automatic redirect I got working with v2 is not working with v3.

So basically the hook isn't getting the last value automatically, you need to refresh the page to get the latest auth state.

@darkmatter18
Copy link
Member

@imjulianeral Let's have an in-person call.
Please setup a call best on your time
https://calendly.com/arkadip/react-auth-kit

@slugiscool99
Copy link

Same problem here - can help if needed

@imjulianeral
Copy link

imjulianeral commented Jan 17, 2024

@darkmatter18 Sure thing!

@imjulianeral
Copy link

This is a repo which reproduces this issue.

https://github.com/imjulianeral/react-auth-kit-state-bug

@jaroslavhuss
Copy link

Any update on this? @darkmatter18? Using "@auth-kit/react-router": "^3.0.2-alpha.19" none of the hooks singIn/signOut causes rerender of useIsAuthenticated(). As @imjulianeral mentioned - windows muset be reloaded in order to get the state.

@kennethhaspeel
Copy link

kennethhaspeel commented Feb 20, 2024

I think i'm having the same issue. I'm using react-auth-kit 3.1.2

Before logging in:
notloggedin
Afte logging in, the cookies are set but nothing rerendered:
loggedin
After refreshing the page manually

loggedinrefresh

@ThaerHindawi
Copy link

I have the same problem.
Is there any new update?

@kennethhaspeel
Copy link

kennethhaspeel commented Feb 28, 2024

I don't think anything will change. It seems the current version doesn't use state so there is no state update.

I draw this conclusion from this: https://github.com/react-auth-kit/react-auth-kit/issues/1558

@imjulianeral
Copy link

@kennethhaspeel Wow, that's not what the mantainer said to me on our meet. Maybe the right move is to stick with v2.

@Odinaev444
Copy link

Odinaev444 commented Mar 7, 2024

Hi.
For those who still on version 3.1.2 and still get this issue, please make sure, you are invoking the useIsAuthenticated hook correctly.
When you use it like this :

const isAuthenticated = useIsAuthenticated();

it won't return you the result of you auth state, but instead it returns you function, so to fix it you should invoke it twice:

const isAuthenticated = useIsAuthenticated()();

here is the fixed commit : bde86ef

or just update the package and i hope it will work.

Thanks.

@mahelbir
Copy link

I have the same problem.
Is there any new update?

@darkmatter18 darkmatter18 added the enhancement New feature or request label Apr 25, 2024
@darkmatter18
Copy link
Member

The fix is coded on the master branch. Please wait for few more days for upcoming release

@rorosaurus
Copy link

Is there a temporary workaround we can use before V4 release?

@kennethhaspeel
Copy link

Is there a temporary workaround we can use before V4 release?

Have you tried the workaround @Odinaev444 mentioned? I'm not using this in my current project anymore (but will use it in future projects) so not sure if it works for your problem but I remember it working for me two months ago

@kvandake
Copy link

I also have a similar problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests