-
Notifications
You must be signed in to change notification settings - Fork 26
Authentication. #14
Comments
I wanted to do it this weekend but I have lot of work to do. I should be able to implement the auth until the end of December. :) |
I'm trying without Redux, but I'm stucked here: https://stackoverflow.com/questions/47655399/react-apollo-2-graphql-authentication-how-to-re-render-component-after-login |
@johnunclesam I will post an answer in like 30 minutes. Gotta get that 100 :D |
I hope! |
@johnunclesam I just posted my answer. I hope it helps. :) I really need to add the authentication here to because it is quite hard to make it the right way and most of the projects need it. |
I read you answer. Do you think there is no way to work without App state? Just with Apollo 2? Also I read online that many people are turning off Redux with Apollo 2. But I don't understand how! This problem is a basic one. Doesn't it? Can you show me an example WITH Redux? |
It is perfectly to fine use redux. Redux is a fancy state management I believe that you want to store client side data in redux and server side data on Apollo server. People are turning off redux because Apollo 2 does not have redux reducer anymore. Using the redux is perfectly fine though. |
@johnunclesam Nice collaboration. I just edited the answer now the code should be correct. |
@developer239 No. It still doesn't work. And plus I think it's not the right direction unfortunately. |
https://codesandbox.io/s/0y3jl8znw It's a lot better, but maybe instaed of check the component state |
You are making things too complicated for no reason. What exactly happens when you call graphql query? Cache first? Cache only? Network first? I get your point but I don't think that using cache instead of react / redux state is a good practice. I might be wrong though. However cache should make fetching values from API faster. You shouldn't rely on values in the cache. React / Redux state and Apollo cache are two different things. |
Its always cahe-first but I can choose my own I think Apollo 2 with I get your point for using Redux. Ok. I wanna try. I know Redux enough. Can I ask you how to query from Redux reducers? So I can use it like this:
But how? Is this whay do you mean? |
I get your point: CLIENT state for the entire App is necessary. I get your point. You are simply RIGHT. So now the question: HOW? How can I query my Apollo cache with Redux dispatch and also use In your files in master I can't find this. Am I wrong? |
Maybe something here? apollographql/apollo-client#2273 |
Well the confusing thing is that I dont use I believe I will use I am quite confused right now to be honest because you are not the first person who told me that they don't need to use redux with apollo client 2. I will definitely try to find out what are the options. In your case you don't need redux because your application is really small. You can just store the shared information in This is also a great issue in official apollo client repo: I will definitely take a look at this thing if I am going to work with authorization in the future: |
Are you adding confusion on confusion?! :):):):):):) Can you imagine a way to what I asked? My app is big or not I wanna use Redux in parallel with Apollo. And I wanna fetch data in Apollo with queries through Redux reducers... They don't have to be connected. Is it clear now? |
Or maybe we can fix it with writeQuery and readQuery but we still need Query presence in cache as them present in backend. This is the problem. |
@johnunclesam https://codesandbox.io/s/0y3jl8znw
I had to call the You have to differentiate between values that are important for client and server and their differences. We can for example fetch user data from server every time we need them. However we have to know if user is logged in client (react / redux state). |
I can use the localstorage for authorization header. But now we are talking about many problems. Can we fix one by one:
|
Like your counter example. I can use redux for states and client data and Apollo for caching backend data. Just I don't know how to start fetching Apollo with redux reducer. Is there a way? Redux-thunk? |
Any maybe something like "connect" HOC with "graphql" HOC. |
@johnunclesam Dude, I spent about 2 hours helping you with your application and you gave the reward to someone else. 😄 |
Can you introduce authentication mechanism?
The text was updated successfully, but these errors were encountered: