{"id":5655,"date":"2020-01-15T06:06:30","date_gmt":"2020-01-14T21:06:30","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=5655"},"modified":"2020-03-03T04:59:41","modified_gmt":"2020-03-02T19:59:41","slug":"%e3%82%b3%e3%83%94%e3%83%9a%e3%81%a7ok%ef%bc%81express%e3%81%ab%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e6%a9%9f%e8%83%bd%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=5655","title":{"rendered":"\u30b3\u30d4\u30da\u3067OK\uff01Express\u306b\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u524d\u3005\u56de\u306e\u8a18\u4e8b\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=5582\">\u4fdd\u5b58\u7248\uff01\u300csequelize\u300d\u30e2\u30c7\u30eb\u306e\u4f7f\u3044\u65b9\u5b9f\u4f8b\u30fb\u516853\u4ef6<\/a>\u300d\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u64cd\u4f5c\u65b9\u6cd5\u3092\u7db2\u7f85\u3057\u305f\u5185\u5bb9\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u7d50\u679c\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u95a2\u9023\u3067\uff11\u3064\u30b5\u30a4\u30c8\u958b\u767a\u306b\u306f\u91cd\u8981\u306a\u6a5f\u80fd\u3092\u601d\u3044\u3064\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u306f\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u3084\u306f\u308a\u3001\u3042\u308b\u7a0b\u5ea6\u306e\u898f\u6a21\u306e\u30b5\u30a4\u30c8\u3068\u306a\u308b\u3068\u30e6\u30fc\u30b6\u30fc\u304c\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u500b\u4eba\u7684\u306a\u60c5\u5831\u3092\u7ba1\u7406\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3001\u3053\u306e\u6a5f\u80fd\u306f\u5916\u305b\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f\u300c<strong>Express<\/strong>\u300d\u3068\u6709\u540d\u306a\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u30d1\u30c3\u30b1\u30fc\u30b8\u300c<strong>Passport.js<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u306a\u304a\u3001\u4eca\u56de\u306f\u5c11\u3057\u5185\u5bb9\u304c\u8907\u96d1\u306a\u90e8\u5206\u3082\u591a\u304b\u3063\u305f\u305f\u3081\u3001<code>async<\/code>\u3084<code>await<\/code>\u3092\u4f7f\u308f\u305a\u300c<strong>\u3067\u304d\u308b\u3060\u3051\u30b7\u30f3\u30d7\u30eb<\/strong>\u300d\u306a\u30b3\u30fc\u30c9\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u3002\uff08\u521d\u5fc3\u8005\u306b\u3082\u3084\u3055\u3057\u3044\u8a18\u4e8b\u3065\u304f\u308a\u3001\u5fc3\u639b\u3051\u3066\u307e\u3059\ud83d\udc4d\uff09<\/p>\n<p>\u3010\u8ffd\u8a18\uff1a2020.3.3\u3011\u5225\u8a18\u4e8b\u3068\u3057\u3066\u516c\u958b\u3057\u3066\u3044\u305f\u300c<strong>\u6b21\u56de\u304b\u3089\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\uff08Remember me\uff09<\/strong>\u300d\u6a5f\u80fd\u3068\u7d71\u5408\u3057\u3066\u52a0\u7b46\u30fb\u4fee\u6b63\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2595 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong>\u00a0Node.js 8.10\u3001Express 4.1<\/p>\n<h1>\u524d\u63d0\u3068\u3057\u3066<\/h1>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u3059\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u300c<strong>Sequelize<\/strong>\u300d\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u524d\u63d0\u3067\u3059\u3002\u8a73\u3057\u304f\u306f\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=5546\" target=\"_blank\" rel=\"noopener noreferrer\">Node.js\u306bDB\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3001Seed\u3001\u30e2\u30c7\u30eb\u3092\u7528\u610f\u3059\u308b\u300cSequelize\u300d<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u306a\u304a\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u306f\u300c<strong>mustache<\/strong>\u300d\u3092\u4f7f\u3044\u307e\u3059\u3002\u3053\u3061\u3089\u3082\u3001\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=5485\">Express\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u57fa\u672c\u306e\u307e\u3068\u3081<\/a>\u300d\u304c\u53c2\u8003\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u306f\u3001\u4e00\u822c\u7684\u306b\u3088\u304f\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3068\u3057\u3066\u4f7f\u308f\u308c\u308b\u3001<\/p>\n<p><strong>\u300c\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u300d + \u300c\u6697\u53f7\u5316\u3055\u308c\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u300d<\/strong><\/p>\n<p>\u3067\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u306e\u3067\u3001\u4ee5\u4e0b\uff15\u3064\uff08\uff0b\uff11\uff09\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>\u3010\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u30d1\u30c3\u30b1\u30fc\u30b8\u3011<\/strong><\/p>\n<pre><strong>npm install --save passport<\/strong><\/pre>\n<pre><strong>npm install --save passport-local<\/strong><\/pre>\n<p><strong>\u3010\u6697\u53f7\u5316\u30d1\u30c3\u30b1\u30fc\u30b8\u3011<\/strong><\/p>\n<pre><strong>npm install --save bcrypt<\/strong><\/pre>\n<p><strong>\u3010Session\u3001Flash\u30e1\u30c3\u30bb\u30fc\u30b8\u7528\u30d1\u30c3\u30b1\u30fc\u30b8\u3011<\/strong><\/p>\n<pre><strong>npm install --save express-session<\/strong><\/pre>\n<pre><strong>npm install --save connect-flash<\/strong><\/pre>\n<p><strong>\u3010Cookie\u7528\u30d1\u30c3\u30b1\u30fc\u30b8\u3011<\/strong><\/p>\n<pre><strong>npm i --save cookie-parser<\/strong><\/pre>\n<p>\u203b\u306a\u304a\u3001\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u300c\u6b21\u56de\u304b\u3089\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b\u300d\u6a5f\u80fd\u3092\u4f7f\u3046\u5834\u5408\u306e\u307f\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u6e96\u5099\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u7ba1\u7406\u3059\u308b<code>Users<\/code>\u30c6\u30fc\u30d6\u30eb\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>npx sequelize model:generate --name User --attributes name:string,email:string,password:string,rememberToken:string<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>\/models<\/code>\u3068<code>\/migrations<\/code>\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u305d\u306e\u307e\u307e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>npx sequelize db:migrate<\/strong><\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6010\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/express_auth_1.png\" alt=\"\" width=\"353\" height=\"294\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/express_auth_1.png 353w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/express_auth_1-300x250.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/p>\n<p>\u7d9a\u3044\u3066\u3001\u958b\u767a\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u3092\u7528\u610f\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<span style=\"font-size: 1rem;\">\u307e\u305a\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<\/span><code>Seed<\/code><span style=\"font-size: 1rem;\">\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/span><\/p>\n<pre><strong>npx sequelize seed:generate --name test-users<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u300c<strong>seeders\/**************-test-users.js<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>'use strict';\r\n<strong>const bcrypt = require('bcrypt');<\/strong>\r\n\r\nmodule.exports = {\r\n  up: (queryInterface, Sequelize) =&gt; {\r\n    const now = new Date();\r\n    return queryInterface.bulkInsert('Users', [\r\n      {\r\n        name: '\u592a\u90ce',\r\n        email: 'taro@example.com',\r\n        <strong>password: bcrypt.hashSync('secret', bcrypt.genSaltSync(8)),<\/strong>\r\n        createdAt: new Date(),\r\n        updatedAt: new Date()\r\n      },\r\n    ], {});\r\n  },\r\n\r\n  down: (queryInterface, Sequelize) =&gt; {\r\n    return queryInterface.bulkDelete('Users', null, {});\r\n  }\r\n};\r\n<\/pre>\n<p>\u30b3\u30fc\u30c9\u3092\u4fdd\u5b58\u3057\u305f\u3089\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>npx sequelize db:migrate<\/strong><\/pre>\n<p><code>Users<\/code>\u30c6\u30fc\u30d6\u30eb\u306f\u3001\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5657\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_2.png\" alt=\"\" width=\"997\" height=\"269\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_2.png 997w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_2-300x81.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_2-768x207.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<div id=\"login\"><\/div>\n<h1>\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u306e\u672c\u4f53\u3092\u3064\u304f\u308b<\/h2>\n<p>\u307e\u305a\u306f\u3001\u300c<strong>Passport.js<\/strong>\u300d\u3067\u5b9f\u969b\u306b\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u90e8\u5206\u3092\u300c<strong>auth.js<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u30eb\u30fc\u30c8\u30d5\u30a9\u30eb\u30c0\u306b\u3064\u304f\u308a\u3001\u3053\u306e\u4e2d\u3067\u5b9f\u88c5\u3057\u307e\u3059\u3002\uff08\u3068\u3044\u3046\u306e\u3082\u3001\u30e1\u30a4\u30f3\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5168\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3068\u9577\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u4fdd\u5b88\u7ba1\u7406\u304c\u3057\u306b\u304f\u304f\u306a\u308b\u305f\u3081\u3067\u3059\ud83d\ude2b\uff09<\/p>\n<pre>const express = require('express');\r\nconst app = express();\r\nconst bcrypt = require('bcrypt');\r\nconst passport = require('passport');\r\nconst LocalStrategy = require('passport-local').Strategy;\r\nconst User = require('.\/models').User;\r\n\r\npassport.use(new LocalStrategy({\r\n    usernameField: 'email',\r\n    passwordField: 'password'\r\n  }, (email, password, done) =&gt;  {\r\n\r\n    User.findOne({\r\n      where: {\r\n        email: email\r\n      }\r\n    })\r\n    .then(user =&gt; {\r\n\r\n      <strong>if(user &amp;&amp; bcrypt.compareSync(password, user.password)) {\r\n\r\n        return done(null, user);  \/\/ \u30ed\u30b0\u30a4\u30f3\u6210\u529f\r\n\r\n      }<\/strong>\r\n\r\n      throw new Error();\r\n\r\n    })\r\n    .catch(error =&gt; { \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\r\n\r\n      <strong>return done(null, false, { message: '\u8a8d\u8a3c\u60c5\u5831\u3068\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u304c\u3042\u308a\u307e\u305b\u3093\u3002' });<\/strong>\r\n\r\n    });\r\n\r\n}));\r\n\r\n\/\/ Session\r\npassport.serializeUser((user, done) =&gt; {\r\n\r\n  done(null, user);\r\n\r\n});\r\npassport.deserializeUser((user, done) =&gt; {\r\n\r\n  done(null, user);\r\n\r\n});\r\n\r\nmodule.exports = passport;<\/pre>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u300c\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u300d\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97<\/li>\n<li>\u3082\u3057\u30e6\u30fc\u30b6\u30fc\u304c\u5b58\u5728\u3057\u3066\u3044\u305f\u3089\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u4e00\u81f4\u3059\u308b\u304b\u30c1\u30a7\u30c3\u30af<\/li>\n<li>\u30d1\u30b9\u30ef\u30fc\u30c9\u3082\u6b63\u3057\u3051\u308c\u3070\u3001\u30ed\u30b0\u30a4\u30f3\u3059\u308b<\/li>\n<\/ol>\n<p>\u3061\u306a\u307f\u306b\u3001\u3053\u306e\uff13\u3064\u306e\u9805\u76ee\u3067\u3082\u3057\u5931\u6557\u304c\u3042\u308c\u3070\u3001\u300c<strong>\u30a8\u30e9\u30fc\u51e6\u7406<\/strong>\u300d\u3068\u66f8\u304b\u308c\u305f\u90e8\u5206\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u300c<strong>session<\/strong>\u300d\u306e\u90e8\u5206\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u5f8c\u306b\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u90e8\u5206\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>auth.js\u3092\u8aad\u307f\u8fbc\u3080<\/h2>\n<p>\u3067\u306f\u3001\u30e1\u30a4\u30f3\u3068\u306a\u308b\u300c<strong>app.js<\/strong>\u300d\u306b\u623b\u3063\u3066\u5148\u307b\u3069\u3064\u304f\u3063\u305f\u300c<strong>auth.js<\/strong>\u300d\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001\u3055\u3089\u306b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u8a2d\u5b9a\u3092\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>const express = require('express');<\/strong>\r\n<strong>const app = express();<\/strong>\r\n<strong>const passport = require('.\/auth');\r\nconst session = require('express-session');\r\nconst flash = require('connect-flash');\r\n\r\n<\/strong>\/\/ \u30df\u30c9\u30eb\u30a6\u30a7\u30a2<strong>\r\napp.use(express.json());\r\napp.use(express.urlencoded({ extended: true }));\r\napp.use(flash());\r\napp.use(session({\r\n  secret: 'YOUR-SECRET-STRING',\r\n  resave: true,\r\n  saveUninitialized: true\r\n}));\r\napp.use(passport.initialize());\r\napp.use(passport.session());\r\n\r\nconst authMiddleware = (req, res, next) =&gt; {\r\n  if(req.isAuthenticated()) {<\/strong> \/\/ \u30ed\u30b0\u30a4\u30f3\u3057\u3066\u308b\u304b\u30c1\u30a7\u30c3\u30af<strong>\r\n\r\n    next();\r\n\r\n  } else {\r\n\r\n    res.redirect(302, '\/login');\r\n\r\n  }\r\n};<\/strong><\/pre>\n<p>\u306f\u3044\uff01\u3053\u308c\u3067\u30ed\u30b0\u30a4\u30f3\u306e\u672c\u4f53\u306e\u90e8\u5206\u306f\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u7d9a\u3044\u3066\u3001\u5404\u30da\u30fc\u30b8\u306b\u9069\u7528\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h2>\n<p>\u4eca\u56de\u4f5c\u6210\u3059\u308b\u30eb\u30fc\u30c8\u306f\u3001\u4ee5\u4e0b\u306e\uff13\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\u3000\u30fb\u30fb\u30fb\u3000\/login\uff08GET\uff09<\/li>\n<li>\u30ed\u30b0\u30a4\u30f3\u5b9f\u884c\u3000\u30fb\u30fb\u30fb\u3000\/login\uff08POST\uff09<\/li>\n<li>\u30ed\u30b0\u30a4\u30f3\u6210\u529f\u5f8c\u306e\u30da\u30fc\u30b8\u3000\u30fb\u30fb\u30fb\u3000\/user\uff08GET\uff09\u203b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u306a\u3044\u3068\u5f37\u5236\u7684\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/li>\n<\/ul>\n<p>\u3067\u306f\u3001\u300c<strong>app.js<\/strong>\u300d\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>\/\/ \u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\r\n<strong>app.get('\/login', (req, res) =&gt; {\r\n  const errorMessage = req.flash('error').join('&lt;br&gt;');\r\n  res.render('login\/form', {\r\n    errorMessage: errorMessage\r\n  });\r\n});\r\n<\/strong>\r\n\/\/ \u30ed\u30b0\u30a4\u30f3\u5b9f\u884c\r\n<strong>app.post('\/login',\r\n  passport.authenticate('local', {\r\n    successRedirect: '\/user',\r\n    failureRedirect: '\/login',\r\n    failureFlash: true,\r\n    badRequestMessage: '\u300c\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u300d\u3068\u300c\u30d1\u30b9\u30ef\u30fc\u30c9\u300d\u306f\u5fc5\u9808\u5165\u529b\u3067\u3059\u3002'\r\n  })\r\n);\r\n<\/strong>\r\n\/\/ \u30ed\u30b0\u30a4\u30f3\u6210\u529f\u5f8c\u306e\u30da\u30fc\u30b8\r\n<strong>app.get('\/user', authMiddleware, (req, res) =&gt; {\r\n  const user = req.user;\r\n  res.send('\u30ed\u30b0\u30a4\u30f3\u5b8c\u4e86\uff01');\r\n});<\/strong><\/pre>\n<p>\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u304c\uff12\u70b9\u3067\u3059\u3002<\/p>\n<p>\uff11\u3064\u76ee\u306f\u3001\u300c<strong>\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0<\/strong>\u300d\u306b\u3042\u308b<code>req.flash('error')<\/code>\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u306b\u5931\u6557\u3057\u305f\u3068\u304d\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092<code>session<\/code>\u304b\u3089\u53d6\u5f97\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3082\u3046\u3072\u3068\u3064\u304c\u3001\u300c<strong>\u30ed\u30b0\u30a4\u30f3\u6210\u529f\u5f8c\u306e\u30da\u30fc\u30b8<\/strong>\u300d\u306e<code>authMiddleware<\/code>\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u5148\u307b\u3069\u8a2d\u5b9a\u3057\u305f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3067\u3001\u300c<strong>\/user<\/strong>\u300d\u3068\u3044\u3046\u30da\u30fc\u30b8\u3067\u306f\u30ed\u30b0\u30a4\u30f3\u3092\u3057\u3066\u3044\u306a\u3051\u308c\u3070\u5f37\u5236\u7684\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e\u30eb\u30fc\u30c8\u3067\u8a2d\u5b9a\u3057\u305f\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\u7528\u306e\u30d3\u30e5\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u300c<strong>views\/login\/form.mst<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;!doctype html&gt;\r\n&lt;html lang=\"ja\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"utf-8\"&gt;\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\r\n    &lt;title&gt;\u30ed\u30b0\u30a4\u30f3\u30fb\u30d5\u30a9\u30fc\u30e0&lt;\/title&gt;\r\n    &lt;link href=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.4.1\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\" class=\"mt-4\"&gt;\r\n    &lt;div class=\"row justify-content-center\"&gt;\r\n        &lt;div class=\"col-md-8\"&gt;\r\n            &lt;div class=\"card\"&gt;\r\n                &lt;div class=\"card-header\"&gt;\u30ed\u30b0\u30a4\u30f3\u30fb\u30d5\u30a9\u30fc\u30e0&lt;\/div&gt;\r\n                &lt;div class=\"card-body\"&gt;\r\n                    <strong>&lt;form method=\"POST\" action=\"\/login\"&gt;<\/strong>\r\n<strong>                        &lt;div class=\"form-group row\"&gt;<\/strong>\r\n<strong>                            &lt;label for=\"email\" class=\"col-md-4 col-form-label text-md-right\"&gt;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9&lt;\/label&gt;<\/strong>\r\n<strong>                            &lt;div class=\"col-md-6\"&gt;<\/strong>\r\n<strong>                                &lt;input id=\"email\" type=\"text\" class=\"form-control\" name=\"email\" autofocus&gt;<\/strong>\r\n<strong>                                {{ #errorMessage }}<\/strong>\r\n<strong>                                &lt;div class=\"alert alert-danger\"&gt;<\/strong>\r\n<strong>                                    {{ errorMessage }}<\/strong>\r\n<strong>                                &lt;\/div&gt;<\/strong>\r\n<strong>                                {{ \/errorMessage }}<\/strong>\r\n<strong>                            &lt;\/div&gt;<\/strong>\r\n<strong>                        &lt;\/div&gt;<\/strong>\r\n<strong>                        &lt;div class=\"form-group row\"&gt;<\/strong>\r\n<strong>                            &lt;label for=\"password\" class=\"col-md-4 col-form-label text-md-right\"&gt;\u30d1\u30b9\u30ef\u30fc\u30c9&lt;\/label&gt;<\/strong>\r\n<strong>                            &lt;div class=\"col-md-6\"&gt;<\/strong>\r\n<strong>                                &lt;input id=\"password\" type=\"password\" class=\"form-control\" name=\"password\"&gt;<\/strong>\r\n<strong>                            &lt;\/div&gt;<\/strong>\r\n<strong>                        &lt;\/div&gt;<\/strong>\r\n<strong>                        &lt;div class=\"form-group row mb-0\"&gt;<\/strong>\r\n<strong>                            &lt;div class=\"col-md-8 offset-md-4\"&gt;<\/strong>\r\n<strong>                                &lt;button type=\"submit\" class=\"btn btn-primary\"&gt;\u30ed\u30b0\u30a4\u30f3&lt;\/button&gt;<\/strong>\r\n<strong>                            &lt;\/div&gt;<\/strong>\r\n<strong>                        &lt;\/div&gt;<\/strong>\r\n<strong>                    &lt;\/form&gt;<\/strong>\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001<code>mustache<\/code>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u3046\u305f\u3081\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8a2d\u5b9a\u306b\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>const mustacheExpress = require('mustache-express');\r\napp.engine('mst', mustacheExpress());\r\napp.set('view engine', 'mst');\r\napp.set('views', __dirname + '\/views');<\/strong><\/pre>\n<h2>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u300c<strong>\/login<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u30d6\u30e9\u30a6\u30b6\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5660\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_3.png\" alt=\"\" width=\"831\" height=\"272\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_3.png 831w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_3-300x98.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_3-768x251.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u307e\u305a\u306f\u4f55\u3082\u5165\u529b\u3057\u306a\u3044\u3067\u9001\u4fe1\u3057\u3066\u307f\u307e\u3059\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5661\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_4.png\" alt=\"\" width=\"829\" height=\"353\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_4.png 829w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_4-300x128.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_4-768x327.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u3046\u307e\u304f\u30a8\u30e9\u30fc\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n\u3067\u306f\u6b21\u306b\u3001\u9593\u9055\u3063\u305f\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u3092\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5662\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_5.png\" alt=\"\" width=\"825\" height=\"330\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_5.png 825w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_5-300x120.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_5-768x307.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u3053\u3061\u3089\u3082\u3046\u307e\u304f\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n\u3067\u306f\u6700\u5f8c\u306b\u3001\u6b63\u3057\u3044\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u3092\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5664\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_6.png\" alt=\"\" width=\"470\" height=\"79\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_6.png 470w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/01\/express_auth_6-300x50.png 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<p>\u306f\u3044\uff01<br \/>\n\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u3066\u30ed\u30b0\u30a4\u30f3\u5fc5\u9808\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u306a\u304a\u3001\u300c\u6b21\u56de\u304b\u3089\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u300d\u6a5f\u80fd\u306f<a href=\"#remember_me\">\u6b21\u56de\u304b\u3089\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u30ed\u30b0\u30a2\u30a6\u30c8\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/h1>\n<p>\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3092\u30ed\u30b0\u30a2\u30a6\u30c8\u3055\u305b\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30eb\u30fc\u30c8\u3092\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>app.get('\/logout', (req, res) =&gt; {\r\n  <strong>req.logout();<\/strong>\r\n  res.redirect('\/login');\r\n});<\/pre>\n<div id=\"remember_me\"><\/div>\n<h1>\u6b21\u56de\u304b\u3089\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3059\u308b\u6a5f\u80fd\u3092\u4f5c\u308b<\/h1>\n<h2>\u6e96\u5099\u3059\u308b<\/h2>\n<p>\u307e\u305a\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3001\u5fc5\u8981\u306a\u5024\u3092<code>app.js<\/code>\u306b\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>const cookieParser = require('cookie-parser');\r\nconst crypto = require('crypto');\r\n\r\napp.use(cookieParser());\r\n\r\n\/\/ \u6697\u53f7\u5316\u306b\u3064\u304b\u3046\u30ad\u30fc\r\nconst APP_KEY = 'YOUR-SECRET-KEY';<\/strong><\/pre>\n<p>\u203b\u306a\u304a\u3001<code>APP_KEY<\/code>\u306f\u672c\u6765<code>.env<\/code>\u306a\u3069\u3067\u4e00\u5143\u7ba1\u7406\u3059\u308b\u3079\u304d\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u7701\u7565\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u308b<\/h2>\n<p>\u300c<a href=\"#login\">\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\u300d\u3067\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u308a\u307e\u3057\u305f\u304c\u3001\u300c<strong>\u6b21\u56de\u304b\u3089\u7701\u7565<\/strong>\u300d\u3059\u308b\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u304c\u306a\u3044\u306e\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002\uff08<strong>\u592a\u5b57<\/strong>\u304c\u8ffd\u52a0\u3057\u305f\u90e8\u5206\u3067\u3059\uff09<\/p>\n<pre>&lt;!doctype html&gt;\r\n&lt;html lang=\"ja\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"utf-8\"&gt;\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\r\n    &lt;title&gt;\u30ed\u30b0\u30a4\u30f3\u30fb\u30d5\u30a9\u30fc\u30e0&lt;\/title&gt;\r\n    &lt;link href=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.4.1\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\" class=\"mt-4\"&gt;\r\n    &lt;div class=\"row justify-content-center\"&gt;\r\n        &lt;div class=\"col-md-8\"&gt;\r\n            &lt;div class=\"card\"&gt;\r\n                &lt;div class=\"card-header\"&gt;\u30ed\u30b0\u30a4\u30f3\u30fb\u30d5\u30a9\u30fc\u30e0&lt;\/div&gt;\r\n                &lt;div class=\"card-body\"&gt;\r\n                    &lt;form method=\"POST\" action=\"\/login\"&gt;\r\n                        &lt;div class=\"form-group row\"&gt;\r\n                            &lt;label for=\"email\" class=\"col-md-4 col-form-label text-md-right\"&gt;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9&lt;\/label&gt;\r\n                            &lt;div class=\"col-md-6\"&gt;\r\n                                &lt;input id=\"email\" type=\"text\" class=\"form-control\" name=\"email\" autofocus&gt;\r\n                                {{ #errorMessage }}\r\n                                &lt;div class=\"alert alert-danger\"&gt;\r\n                                    {{ errorMessage }}\r\n                                &lt;\/div&gt;\r\n                                {{ \/errorMessage }}\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        &lt;div class=\"form-group row\"&gt;\r\n                            &lt;label for=\"password\" class=\"col-md-4 col-form-label text-md-right\"&gt;\u30d1\u30b9\u30ef\u30fc\u30c9&lt;\/label&gt;\r\n                            &lt;div class=\"col-md-6\"&gt;\r\n                                &lt;input id=\"password\" type=\"password\" class=\"form-control\" name=\"password\"&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                        <strong>&lt;div class=\"form-group row\"&gt;<\/strong>\r\n<strong>                            &lt;div class=\"col-md-6 offset-md-4\"&gt;<\/strong>\r\n<strong>                                &lt;div class=\"form-check\"&gt;<\/strong>\r\n<strong>                                    &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"remember\" value=\"1\" id=\"remember\"&gt;<\/strong>\r\n<strong>                                    &lt;label class=\"form-check-label\" for=\"remember\"&gt;<\/strong>\r\n<strong>                                        \u6b21\u56de\u304b\u3089\u7701\u7565<\/strong>\r\n<strong>                                    &lt;\/label&gt;<\/strong>\r\n<strong>                                &lt;\/div&gt;<\/strong>\r\n<strong>                            &lt;\/div&gt;<\/strong>\r\n<strong>                        &lt;\/div&gt;<\/strong>\r\n                        &lt;div class=\"form-group row mb-0\"&gt;\r\n                            &lt;div class=\"col-md-8 offset-md-4\"&gt;\r\n                                &lt;button type=\"submit\" class=\"btn btn-primary\"&gt;\u30ed\u30b0\u30a4\u30f3&lt;\/button&gt;\r\n                            &lt;\/div&gt;\r\n                        &lt;\/div&gt;\r\n                    &lt;\/form&gt;\r\n                &lt;\/div&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u308c\u3092\u30d6\u30e9\u30a6\u30b6\u3067\u8868\u793a\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5953\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_9.png\" alt=\"\" width=\"640\" height=\"225\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_9.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_9-300x105.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u6642\u306b\u30c8\u30fc\u30af\u30f3\u3092\u4fdd\u5b58\u3059\u308b\u90e8\u5206<\/h2>\n<p>\u7d9a\u3044\u3066\u540c\u3058\u304f<a href=\"#login\">\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\u3067\u3064\u304f\u3063\u305f\u30eb\u30fc\u30c8\u306e<code>app.post('\/login', ...)<\/code>\u306e\u90e8\u5206\u3092\u5909\u66f4\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u6642\u306b\u30c8\u30fc\u30af\u30f3\u3092\u4fdd\u5b58\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>app.post('\/login',\r\n  passport.authenticate('local', {\r\n    failureRedirect: '\/login',\r\n    failureFlash: true,\r\n    badRequestMessage: '\u300c\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u300d\u3068\u300c\u30d1\u30b9\u30ef\u30fc\u30c9\u300d\u306f\u5fc5\u9808\u5165\u529b\u3067\u3059\u3002'\r\n  }),\r\n  (req, res, next) =&gt; {\r\n\r\n    if(!req.body.remember) {  \/\/ \u6b21\u56de\u3082\u30ed\u30b0\u30a4\u30f3\u3092\u7701\u7565\u3057\u306a\u3044\u5834\u5408\r\n\r\n      res.clearCookie('remember_me');\r\n      return next();\r\n\r\n    }\r\n\r\n    const user = req.user;\r\n    const rememberToken = crypto.randomBytes(20).toString('hex'); \/\/ \u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\r\n    const hash = crypto.createHmac('sha256', APP_KEY)\r\n      .update(user.id +'-'+ rememberToken)\r\n      .digest('hex');\r\n    user.rememberToken = rememberToken;\r\n    user.save();\r\n\r\n    res.cookie('remember_me', rememberToken +'|'+ hash, {\r\n      path: '\/',\r\n      maxAge: 5 * 365 * 24 * 60 * 60 * 1000 \/\/ 5\u5e74\r\n    });\r\n\r\n    return next();\r\n\r\n  },\r\n  (req, res) =&gt; {\r\n\r\n    res.redirect('\/user');\r\n\r\n  }\r\n);<\/strong><\/pre>\n<p>\u8ffd\u52a0\u3057\u305f\u90e8\u5206\u3067\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u30ed\u30b0\u30a4\u30f3\u304c\u6210\u529f\u3057\u305f\u3089\u3001\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3092\u6709\u52b9\u306b\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af<\/li>\n<li>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u5834\u5408\u306f\u3001\u30c8\u30fc\u30af\u30f3\u3068\u30cf\u30c3\u30b7\u30e5\u5024\u3092\u3064\u304f\u308b<\/li>\n<li>\u30c8\u30fc\u30af\u30f3\u3092User\u30c6\u30fc\u30d6\u30eb\u306b\u4fdd\u5b58<\/li>\n<li>\u30c8\u30fc\u30af\u30f3\uff06\u30cf\u30c3\u30b7\u30e5\u5024\u3092Cookie\u306b\u4fdd\u5b58<\/li>\n<\/ol>\n<p>\u306a\u304a\u3001\u30c8\u30fc\u30af\u30f3\u306e\u6709\u52b9\u671f\u9593\u306f\uff15\u5e74\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u30e1\u30a4\u30f3\u306e\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u5909\u66f4\u3059\u308b\u306e\u306f\u3001\u300c<a href=\"#login\">\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\u300d\u3067\u4f5c\u3063\u305f<code>authMiddleware<\/code>\u3067\u3059\u3002\uff08<strong>\u592a\u5b57<\/strong>\u304c\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u305f\u90e8\u5206\u3067\u3059\uff09<\/p>\n<pre>const authMiddleware = (req, res, next) =&gt; {\r\n  if(req.isAuthenticated()) {\r\n\r\n    next();\r\n\r\n  }<strong> else if(req.cookies.remember_me) {\r\n\r\n    const [rememberToken, hash] = req.cookies.remember_me.split('|');\r\n\r\n    User.findAll({\r\n      where: {\r\n        rememberToken: rememberToken\r\n      }\r\n    }).then(users =&gt; {\r\n\r\n      for(let i in users) {\r\n\r\n        const user = users[i];\r\n\r\n        const verifyingHash = crypto.createHmac('sha256', APP_KEY)\r\n          .update(user.id +'-'+ rememberToken)\r\n          .digest('hex');\r\n\r\n        if(hash === verifyingHash) {\r\n\r\n          return req.login(user, () =&gt; {\r\n\r\n            \/\/ \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u7684\u306f\u3053\u3053\u3067 remember_me \u3092\u518d\u5ea6\u66f4\u65b0\u3059\u3079\u304d\r\n\r\n            next();\r\n\r\n          });\r\n\r\n        }\r\n\r\n\r\n      }\r\n\r\n      res.redirect(302, '\/login');\r\n\r\n    });\r\n\r\n  }<\/strong> else {\r\n\r\n    res.redirect(302, '\/login');\r\n\r\n  }\r\n};<\/pre>\n<p><strong>\u3010\u8ffd\u8a18\uff1a2020.02.26\u3011every()\u3092\u4f7f\u3063\u305f\u30eb\u30fc\u30d7\u3067\u51e6\u7406\u304c\u7d42\u4e86\u3057\u306a\u3044\u3068\u3044\u3046\u4e0d\u5177\u5408\u304c\u767a\u751f\u3042\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u901a\u5e38\u306efor()\u30eb\u30fc\u30d7\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002\u3054\u4e0d\u4fbf\u3092\u304a\u304b\u3051\u3057\u3066\u7533\u3057\u8a33\u3054\u3056\u3044\u307e\u305b\u3093\ud83d\ude2b<\/strong><\/p>\n<p>\u8ffd\u52a0\u3057\u305f\u30b3\u30fc\u30c9\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u306e\u306f\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u307e\u305aCookie\u306e\u30c7\u30fc\u30bf\u304b\u3089\u30c8\u30fc\u30af\u30f3\u3068\u30cf\u30c3\u30b7\u30e5\u5024\u3092\u53d6\u5f97<\/li>\n<li>\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066\u8a72\u5f53\u3059\u308b\u5168\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97<\/li>\n<li>\u30cf\u30c3\u30b7\u30e5\u5024\u3068\u4e00\u81f4\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97<\/li>\n<li>\u624b\u52d5\u3067\u305d\u306e\u30e6\u30fc\u30b6\u30fc\u3092\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u308b<\/li>\n<\/ol>\n<p>\u306a\u304a\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u8907\u6570\u53d6\u5f97\u3057\u3066\u3044\u308b\u306e\u306f\u3001\u4e07\u304c\u4e00\u540c\u3058\u30c8\u30fc\u30af\u30f3\u3092\u6301\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u304c\u5b58\u5728\u3057\u3066\u3082\u3044\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u306b\u3001\u30cf\u30c3\u30b7\u30e5\u5024\u306f\u30e6\u30fc\u30b6\u30fcID\u3092\u542b\u3081\u305f\u6587\u5b57\u5217\u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b\u307e\u305f\u3001\u672c\u6765\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u89b3\u70b9\u304b\u3089\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3092\u3057\u305f\u3089<code>Cookie<\/code>\u306e\u30c8\u30fc\u30af\u30f3\u306f\u65b0\u3057\u3044\u3082\u306e\u306b\u66f4\u65b0\u3059\u308b\u3079\u304d\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u306a\u306e\u3067\u7701\u7565\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306e\u30c6\u30b9\u30c8\u3067\u3059\u304c\u3001\u5148\u306b<code>Chrome<\/code>\u3067<code>Cookie<\/code>\u3092\u7ba1\u7406\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u30da\u30fc\u30b8\u306e\u3069\u3053\u3067\u3082\u3044\u3044\u306e\u3067\u53f3\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u30e1\u30cb\u30e5\u30fc\u304c\u51fa\u308b\u306e\u3067\u300c<strong>\u691c\u8a3c<\/strong>\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08Linux\u7248\u306a\u306e\u3067\u6587\u5b57\u304c\u9055\u3063\u3066\u3044\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\ud83d\ude05\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5946\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_1.png\" alt=\"\" width=\"342\" height=\"277\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_1.png 342w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_1-300x243.png 300w\" sizes=\"auto, (max-width: 342px) 100vw, 342px\" \/><\/p>\n<p><code>DevTool<\/code>\u304c\u958b\u3044\u305f\u3089\u3001\u300c<code>Application \uff1e Cookies<\/code>\u300d\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u305d\u306e\u30b5\u30a4\u30c8\u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b<code>Cookie<\/code>\u306e\u4e00\u89a7\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u3053\u304b\u3089\u5185\u5bb9\u306e\u78ba\u8a8d\u3084\u524a\u9664\u304c\u7c21\u5358\u306b\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5947\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_2.png\" alt=\"\" width=\"722\" height=\"311\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_2.png 722w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_2-300x129.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/p>\n<p>\u3067\u306f\u3001\u4eca\u56de\u306e\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3057\u307e\u3059\uff01<\/p>\n<p><code>\/login<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u3092\u5165\u529b\u3001\u3055\u3089\u306b\u300c<strong>\u6b21\u56de\u304b\u3089\u7701\u7565<\/strong>\u300d\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u3066\u30ed\u30b0\u30a4\u30f3\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5948\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_3.png\" alt=\"\" width=\"559\" height=\"213\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_3.png 559w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_3-300x114.png 300w\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" \/><\/p>\n<p>\u3067\u306f\u3001\u3053\u306e\u6642\u70b9\u3067<code>Cookie<\/code>\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5949\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_5.png\" alt=\"\" width=\"501\" height=\"96\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_5.png 501w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_5-300x57.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/p>\n<p>\u3046\u307e\u304f<code>remember_me<\/code>\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u6b21\u306b\u3053\u306e\u4e2d\u306e\u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u3092\u4fdd\u5b58\u3057\u3066\u3044\u308b<code>connect.sid<\/code>\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5950\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_6.png\" alt=\"\" width=\"500\" height=\"77\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_6.png 500w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_6-300x46.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u72b6\u614b\u3067\u30da\u30fc\u30b8\u3092\u30ea\u30ed\u30fc\u30c9\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5951\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_7.png\" alt=\"\" width=\"129\" height=\"40\" \/><\/p>\n<p>\u306f\u3044\uff01<br \/>\n\u901a\u5e38\u306a\u3089\u30ed\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u3066\u3057\u307e\u3046\u306f\u305a\u304c\u3001\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u306a\u304a\u3001<code>DevTool<\/code>\u3092\u78ba\u8a8d\u3059\u308b\u3068\u65b0\u3057\u3044<code>connect.sid<\/code>\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5952\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_8.png\" alt=\"\" width=\"510\" height=\"95\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_8.png 510w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/express_remember_me_8-300x56.png 300w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u300c<strong>admin<\/strong>\u300d\u300c<strong>owner<\/strong>\u300d\u300c<strong>user<\/strong>\u300d\u306a\u3069\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u3067\u30da\u30fc\u30b8\u306e\u95b2\u89a7\u5236\u9650\u3092\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f7f\u3046\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>const adminAuthMiddleware = (req, res, next) =&gt; {\r\n  if(<strong>req.isAuthenticated() &amp;&amp; req.user.role === 'admin'<\/strong>) {\r\n\r\n    next();\r\n\r\n  } else {\r\n\r\n    res.redirect(302, '\/login');\r\n\r\n  }\r\n};<\/pre>\n<p>\u203b\u3082\u3061\u308d\u3093\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5185\u306b<code>role<\/code>\u3068\u3044\u3046\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u7528\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30eb\u30fc\u30c8\u306f\u3001\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>app.get('\/admin', <strong>adminAuthMiddleware<\/strong>, (req, res) =&gt; {\r\n  \/\/ \u7701\u7565\r\n\r\n});<\/pre>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Express<\/code>\u3092\u4f7f\u3063\u305f\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306fHTTP\u9001\u4fe1\u3067\u30ed\u30b0\u30a4\u30f3\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u8272\u3005\u3068<code>session<\/code>\u95a2\u4fc2\u3067\u30b3\u30fc\u30c9\u304c\u8907\u96d1\u3060\u3063\u305f\u306e\u3067\u3001\u3082\u3057\u304b\u3059\u308b\u3068<code>Ajax<\/code>\u3092\u4f7f\u3063\u305f\u30ed\u30b0\u30a4\u30f3\u306e\u65b9\u304c\u30b9\u30e0\u30fc\u30ba\u306b\u3044\u304f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305f\u3001\u96d1\u611f\u3068\u3057\u3066\u306f\u3001<code>Laravel<\/code>\u3068\u6bd4\u3079\u308b\u3068\u8a18\u8ff0\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u30b3\u30fc\u30c9\u304c\u591a\u3044\u306e\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u306e<code>initialize()<\/code>\u3067\u5fc5\u8981\u6700\u4f4e\u9650\u306f\u3059\u3079\u3066\u5b9f\u884c\u3057\u3066\u304f\u308c\u305f\u3089\u3046\u308c\u3057\u3044\u306a\u30fc\u3001\u306a\u3093\u3066\u30ca\u30de\u30b1\u30e2\u30ce\u30fb\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306e\u79c1\u306f\u601d\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\uff08\u7b11\uff09<\/p>\n<p>\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3059\u3079\u3066\u81ea\u524d\u3067\u7528\u610f\u3059\u308b\u3053\u3068\u3092\u8003\u3048\u308b\u3068\u611f\u8b1d\u611f\u6fc0\uff01\u306b\u306f\u9593\u9055\u3044\u306a\u3044\u306a\u3044\u3067\u3059\u3051\u3069\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\ud83d\ude0a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4445 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u524d\u3005\u56de\u306e\u8a18\u4e8b\u300c\u4fdd\u5b58\u7248\uff01\u300csequelize\u300d\u30e2\u30c7\u30eb\u306e\u4f7f\u3044\u65b9\u5b9f\u4f8b\u30fb\u516853\u4ef6\u300d\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u64cd\u4f5c\u65b9\u6cd5\u3092\u7db2\u7f85\u3057\u305f\u5185\u5bb9\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002 \u305d\u3057\u3066\u3001\u3053\u306e\u8a18 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=5655\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u30b3\u30d4\u30da\u3067OK\uff01Express\u306b\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":5670,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[201,203],"tags":[58],"class_list":["post-5655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-express","category-node-js","tag-58"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5655"}],"version-history":[{"count":12,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5655\/revisions"}],"predecessor-version":[{"id":6015,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5655\/revisions\/6015"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/5670"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}