How to do it...

We will mostly use the same code that we created for the MySQL recipe and add a security layer to validate our access tokens:

  1. The first thing we need to do is to modify our config file (config/index.js), add a security node with the secretKey we are going to use to create our tokens, and add the expiration time of the token:
  export default {    db: {      dialect: 'mysql', // The database engine you want to use      host: 'localhost', // Your host, by default is localhost      database: 'blog', // Your database name      user: 'root', // Your MySQL user, by default is root      password: '123456' // Your MySQL password    },    security: {      secretKey: 'C0d3j0bs', // Secret key      expiresIn: '1h' // Expiration can be: 30s, 30m, 1h, 7d, etc.    }  };
File: config/index.js ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.