2016-03-21 13 views
1

これは私の戦略であり、server.register()で定義されています。私はチュートリアルの作業に基づいています。文字通りコピーされていますが、動作しません。request.auth.session.set(user_info)not working HapiJS

server.auth.strategy('standard', 'cookie', { 
     password: 'somecrazycookiesecretthatcantbeguesseswouldgohere', // cookie secret 
     cookie: 'app-cookie', // Cookie name 
     isSecure: false, // required for non-https applications 
     redirectTo: '/login', 
     ttl: 24 * 60 * 60 * 1000 // Set session to 1 day 
    }); 

    server.auth.default({ 
     strategy: 'standard', 
     mode: 'required', 
     scope: ['admin'] 
    }); 

これは、エラーが発生し、私のログインルートです:

server.route({ 
    method: 'POST', 
    path: '/login', 
    config: { 
     auth: false, 
     validate: { 
      payload: { 
       email: Joi.string().email().required(), 
       password: Joi.string().min(2).max(200).required() 
      } 
     }, 
     handler: function (request, reply) { 

      getValidatedUser(request.payload.email, request.payload.password) 
        .then(function (user) { 

         if (user) { 
          //ERROR OCCURS HERE: IT SAYS SESSION IS UNDEFINED 
          request.auth.session.set(user); 
          return reply('Login Successful!'); 
         } else { 
          return reply(Boom.unauthorized('Bad email or password')); 
         } 

        }); 
//      .catch(function (err) { 
//       return reply(Boom.badImplementation()); 
//      }); 

     } 
    } 
}); 

私はたくさんのことを試してみたが、この部分は、この作品のために重要であると私は同じ問題を持つ人を見つけることができません。助けてください!

+0

は「動かない」あなたを助けるために人々のために十分な情報ではありません。何が起こった、あなたは何を期待していたのですか?エラーメッセージが表示されましたか?彼らは何を言いましたか? –

+0

それはもう解決されません。@mcmoの答えが – Forget

答えて

6

hapi-auth-cookieは、Cookieの設定と消去の方法を変更しました。バージョン5.0.0では、request.cookieAuth.set()およびrequest.cookieAuth.clear()を使用します。チュートリアルのpackage.jsonで使用されているよりも、プラグインの最新バージョンを使用している可能性があります。

ソース: https://github.com/hapijs/hapi-auth-cookie/commit/d233b2a3e4d0f03ef53b91b7929b8dbadbff624c

+0

であることを確認してください。後でドキュメントをチェックしました。それで解決しました。 どうもありがとうございます、それは答えですので、私はそのようにマークします! – Forget