10
10

More than 5 years have passed since last update.

socket.ioでのセッション認証(connect.utils.parseSignedCookiesからの変更)

Posted at

いままでこんな感じでセッション認証行ってたところ

var cookie = require('cookie').cookie.parse(handshake.headers.cookie);
cookie = connect.utils.parseSignedCookies(cookie, 'secret_key');
var sessionId = cookie['cookie_key']

connectがこんなwarning出してるのに気づいた。

connect: utils.parseSignedCookies: this private api moved with cookie-parser

cookie-parser使えってことらしい。なので、こんな感じに変更したらうまくいった

var cookieParser = require('cookie-parser')
var parseCookie = cookieParser('secret_key');

parseCookie(handshake, null, function(err) {
    if (err) {
        return accept('Error parseCookie.', false);
    }

    var sessionId = handshake.signedCookies['cookie_key'];

    // sessionIdを使用してチェック
});


10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10