Contents
はじめに
https://rocky-wildwood-40562.herokuapp.com/
今日こそ完遂しないとなりません。ちょっと焦ってきた。
既知の現象
昨日起きていた現象は以下の通り。
・idがauto incrementになっていない。
・createTable後のカラムの追加がうまくいかない。
> ・idがauto incrementになっていない。
これはmigrations内の書き方に重大な瑕疵が。
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
id: {
type: Sequelize.INTEGER
},こりゃうまくいかないよ。
次。
>・createTable後のカラムの追加がうまくいかない。
これもそもそものSequelizeへの命令を書き損じていた模様。
https://sequelize.org/master/class/lib/dialects/abstract/query-interface.js~QueryInterface.html
公式を参照すると、こういう書き方になります。
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
queryInterface.addColumn('Users', 'wheretogo',
{type: Sequelize.STRING,
after: 'password' // after option is only supported by MySQL
});
queryInterface.addColumn('Users', 'go_date',
{type: Sequelize.DATE,
after: 'wheretogo' // after option is only supported by MySQL
});これで事なきを得ました…が!
肝心の認証メールのURLが無効になってしまう。
タイムゾーンか?
https://qiita.com/ikemura23/items/52ab8a5d260c7ee4d42b
違った。
router.post('/signup', async function(req, res) {
(略)
let verificationUrl = req.get('origin') +'/verify/'+ user.id +'/'+ hash +'?expires='+ expiration;
const signature = crypto.createHmac('sha256', appKey)
.update(verificationUrl)
.digest('hex');
verificationUrl += '&signature='+ signature;
(略)
});
router.get('/verify/:id/:hash', (req, res) => {
(略)
const verificationUrl = 'https://rocky-wildwood-40562.herokuapp.com' + req.originalUrl.split('&signature=')[0];
const signature = crypto.createHmac('sha256', appKey)
.update(verificationUrl)
.digest('hex');
const isCorrectSignature = (signature === req.query.signature);
(略)
});
上のソースで3行目と13行目で作っているverificationUrlが一致していなかったためでした。
\できたー!!/
https://rocky-wildwood-40562.herokuapp.com/

日本語化以外は!w
いっぺん完了として、やっておきたいことあるんでそのうち仕上げます!
しかしSendGrid賢い!
メールの中のURLは https://uxxxxxxxxx.ct.sendgrid.net/ls/click? とかなのに、私のherokuによしなにリダイレクトしてくれる。
herokuのadd onにSendGridいるからクレカ与信取らないと使えないかと思ったけれど、普通に書けば動いた。
また何かに使おう。