PassportJS - Using multiple passports within Express application

前端 未结 1 1030
独厮守ぢ
独厮守ぢ 2020-12-31 14:51

Suppose I need two different passports within one express application (e.g. user & room). So I define two separate vars:

var passport    = require(\'pass         


        
相关标签:
1条回答
  • 2020-12-31 15:30

    The problem your having is that the passport module exports an instantiated Passport object when you require it. And because that object is cached by node when you require it, you get the exact same object every time.

    Luckily, the passport module also gives you a reference to the class, meaning you can do this.

    var Passport = require('passport').Passport,
        passport = new Passport(),
        roomPassport = new Passport();
    

    Now you should have two completely separate passport objects.

    0 讨论(0)
提交回复
热议问题