react-auth-kit icon indicating copy to clipboard operation
react-auth-kit copied to clipboard

useIsAuthenticated hook doesn't cause re-render

Open zarnocha opened this issue 1 year ago • 21 comments

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

zarnocha avatar Jan 09 '24 21:01 zarnocha

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

wiktor-maruszewski avatar Jan 10 '24 16:01 wiktor-maruszewski

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

darkmatter18 avatar Jan 11 '24 16:01 darkmatter18

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.

imjulianeral avatar Jan 12 '24 22:01 imjulianeral

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

darkmatter18 avatar Jan 16 '24 15:01 darkmatter18

Same problem here - can help if needed

slugiscool99 avatar Jan 17 '24 05:01 slugiscool99

@darkmatter18 Sure thing!

imjulianeral avatar Jan 17 '24 17:01 imjulianeral

This is a repo which reproduces this issue.

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

imjulianeral avatar Jan 19 '24 14:01 imjulianeral

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.

jaroslavhuss avatar Jan 26 '24 05:01 jaroslavhuss

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

kennethhaspeel avatar Feb 20 '24 14:02 kennethhaspeel

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

ThaerHindawi avatar Feb 28 '24 15:02 ThaerHindawi

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

kennethhaspeel avatar Feb 28 '24 15:02 kennethhaspeel

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

imjulianeral avatar Feb 28 '24 15:02 imjulianeral

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 : https://github.com/react-auth-kit/react-auth-kit/commit/bde86eff757defe26a6266ea05e287f94836ef8c

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

Thanks.

Odinaev444 avatar Mar 07 '24 11:03 Odinaev444

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

mahelbir avatar Mar 16 '24 19:03 mahelbir

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

darkmatter18 avatar Apr 25 '24 03:04 darkmatter18

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

rorosaurus avatar May 08 '24 00:05 rorosaurus

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

kennethhaspeel avatar May 09 '24 09:05 kennethhaspeel

I also have a similar problem...

kvandake avatar May 31 '24 20:05 kvandake

Will the fix of this issue be released any day?

nikolay-emrikh-stenn avatar Jul 17 '24 09:07 nikolay-emrikh-stenn

i have the same problem, has anybody fixed it?

CinDevFC avatar Jul 24 '24 12:07 CinDevFC