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

get / set cookie from ssr without using server middleware #2215

Closed
agencewebcom opened this issue Nov 23, 2017 · 6 comments
Closed

get / set cookie from ssr without using server middleware #2215

agencewebcom opened this issue Nov 23, 2017 · 6 comments
Labels

Comments

@agencewebcom
Copy link

agencewebcom commented Nov 23, 2017

Hello,
I try to find a solution, but I'm not sure that it really exists. I have a distant api, so I don't need/want to use any api on the server side using server middleware, I just want to set / get cookies or data on local storage from my store.

Is it possible ?

This question is available on Nuxt.js community (#c1952)
@0pt1m1z3r
Copy link

You can get cookies from context.req and set with context.res

@Serhii-the-Dev
Copy link

Serhii-the-Dev commented Nov 24, 2017

Yes, it is. First, you may use nuxt-ommunity/axios-module, it will make all the work automatically. Also you can do it manually, via Nuxt context injection, for example, in the asyncData hook:

async asyncData({req}) {
      const headers = req && req.headers
      const {data} = await axios('/api/entries', {headers: headers})
}

So cookies along with other headers will be proxied to API server from a client, or you may filter only requried header and use it.

@agencewebcom
Copy link
Author

Great!!
Thank you!

@agencewebcom
Copy link
Author

agencewebcom commented Nov 27, 2017

I will use nuxt/axios module to store the token and other informations which will be shared with all my requests, but yes, the module do exactly the same thing you told me.
But, if I want to store some user information and don't want to be limited by the max size of the cookies, it's better to use the local storage, which will be accessible only from the client side, or an express route (such as /server/save-my-data) with server middleware and store it in the session?
If you think that the question is not inherent to post, I will create another one
Thank you

@Geogaddy-labs
Copy link

¿Maybe an example of this? I trying to do the same, i need to storage session cookie

@lock
Copy link

lock bot commented Nov 4, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 4, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants