最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to handle httpOnly cookie authentication in next.js with apollo client - Stack Overflow

programmeradmin1浏览0评论

In my usual experience all single page apps I worked on used JWT as authentication mechanism. I came across api that uses httpOnly cookies for this.

Since we can't access such cookie via javascript to know if it is present or not, how does one handle this in react app?

My initial idea was to track this by setting some sessionStorage upon successful sign in and removing it if I receive an error related to authentication.

But this doesn't work well with next.js server side rendering I believe? We have it set up with apollo client which allows setting custom headers and cache.

Is there a mon way to handle this authentication process with set up above?

In my usual experience all single page apps I worked on used JWT as authentication mechanism. I came across api that uses httpOnly cookies for this.

Since we can't access such cookie via javascript to know if it is present or not, how does one handle this in react app?

My initial idea was to track this by setting some sessionStorage upon successful sign in and removing it if I receive an error related to authentication.

But this doesn't work well with next.js server side rendering I believe? We have it set up with apollo client which allows setting custom headers and cache.

Is there a mon way to handle this authentication process with set up above?

Share Improve this question asked Jul 20, 2018 at 12:04 IljaIlja 46.6k103 gold badges289 silver badges528 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

httpOnly just means that the value can't be read by JavaScript.

So you make an HTTP request to the server and it will return a response with a Set-Cookie header.

Then any future requests will automatically include the cookie.

(Just make sure that you set withCredentials or the equivalent.)

发布评论

评论列表(0)

  1. 暂无评论