How to access global store in a Router Hook

Hey there.

I am using v2 and I try to implement an authentication flow. My purpose is to check if isLoggedIn flag in store is true or false. For this, I want to implement a Router hook (or pipeline, as it is called in v1) but I could not figure out how to do it exactly. connectTo won’t work, I assume because certain lifecycle methods such as bind does not exist for hooks. So any help ( or recommendations for better approaches ) is appreciated :slight_smile:

1 Like

You might have already done this, but have you taken a look at the v2 docs? Towards the end there is a section about authentication using lifecycle hooks :slightly_smiling_face:.

2 Likes

Hey Ivan. Thanks for response :slight_smile:

Yes, I looked at the given example and although it is a good example, I would still want to learn a good way to access the global state.

if you’re talking about the store plugin, inject the store in the hook, subscribe and get the state into a prop and use it for whatever you need it

1 Like