AuthWrapper & AuthFunction Setup #4097
Replies: 1 comment 3 replies
-
@BarishSarac const Logout = (instance) => {
return instance.logoutRedirect();
};
const exampleLogoutComponent = () => {
const { instance } = useMsal();
useEffect(() => {
Logout(instance)
}, []);
return <></>;
}
// Then render exampleLogoutComponent somewhere in your component tree You have a similar issue with the class example you provided. Unless you are rendering AuthFunctions as a component it will not have access to context. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have the below setup in terms of Auth b2c msal 2.0. I'd like to have an auth-functions file so anywhere in any of my applications if I need to get expiration time of the current user's session I can. If I need to logout the user, I can as well utilizing Auth-Functions. Currently with the below setup, no matter what I do I get
Error: Invalid hook call.
error. It is because Main has my whole app and some files in the app are class some are functions. So if I end up calling auth-functions from a class I getError: Invalid hook call.
error. What would be the best way to provide 1 function file , so anywhere in my app I can import and utilize it's functions? I looked intoI have the below AuthWrapper
and below Auth-Functions
If I translate AuthFunctions to a Class (which I'd rather not do)
When I call
this.clb = new AuthFunctions(); this.clb.Logout();
inside constructor, just to see if context works, it does not, I get
undefined
How is the best way to provide group of functions to all my projects regardless they're class, function or any other type files...
Beta Was this translation helpful? Give feedback.
All reactions