2017-11-17 11:17:20 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An asynchronous bootstrap function that runs before
|
|
|
|
* your application gets started.
|
|
|
|
*
|
|
|
|
* This gives you an opportunity to set up your data model,
|
|
|
|
* run jobs, or perform some special logic.
|
|
|
|
*/
|
|
|
|
|
2017-12-04 16:43:24 +01:00
|
|
|
const path = require('path');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const fs = require('fs');
|
|
|
|
const uuid = require('uuid/v4');
|
|
|
|
|
2017-11-17 11:17:20 +01:00
|
|
|
module.exports = cb => {
|
2017-12-04 16:43:24 +01:00
|
|
|
if (!_.get(strapi.plugins['users-permissions'], 'config.jwtSecret')) {
|
|
|
|
try {
|
2017-12-12 15:13:27 +01:00
|
|
|
const jwtSecret = uuid();
|
2017-12-04 16:43:24 +01:00
|
|
|
fs.writeFileSync(path.join(strapi.config.appPath, 'plugins', 'users-permissions', 'config', 'jwt.json'), JSON.stringify({
|
2017-12-12 15:13:27 +01:00
|
|
|
jwtSecret
|
2017-12-04 16:43:24 +01:00
|
|
|
}, null, 2), 'utf8');
|
2017-12-12 15:13:27 +01:00
|
|
|
|
|
|
|
_.set(strapi.plugins['users-permissions'], 'config.jwtSecret', jwtSecret);
|
2017-12-04 16:43:24 +01:00
|
|
|
} catch(err) {
|
|
|
|
strapi.log.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 15:20:13 +01:00
|
|
|
if (!_.get(strapi.plugins['users-permissions'], 'config.grant')) {
|
|
|
|
try {
|
|
|
|
const jwtSecret = uuid();
|
|
|
|
fs.writeFileSync(path.join(strapi.config.appPath, 'plugins', 'users-permissions', 'config', 'grant.json'), JSON.stringify({
|
|
|
|
grant: {
|
|
|
|
facebook: {
|
|
|
|
key: '',
|
|
|
|
secret: '',
|
|
|
|
callback: '/auth/facebook/callback',
|
|
|
|
scope: ['email']
|
|
|
|
},
|
|
|
|
google: {
|
|
|
|
key: '',
|
|
|
|
secret: '',
|
|
|
|
callback: '/auth/google/callback',
|
|
|
|
scope: ['email']
|
|
|
|
},
|
|
|
|
github: {
|
|
|
|
key: '',
|
|
|
|
secret: '',
|
|
|
|
callback: '/auth/github/callback'
|
|
|
|
},
|
|
|
|
linkedin2: {
|
|
|
|
key: '',
|
|
|
|
secret: '',
|
|
|
|
callback: '/auth/linkedin2/callback',
|
|
|
|
custom_params: {
|
|
|
|
'state': ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, null, 2), 'utf8');
|
|
|
|
|
|
|
|
_.set(strapi.plugins['users-permissions'], 'config.grant', grant);
|
|
|
|
} catch(err) {
|
|
|
|
strapi.log.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 16:36:56 +01:00
|
|
|
strapi.plugins['users-permissions'].services.userspermissions.syncSchema(() => {
|
|
|
|
strapi.plugins['users-permissions'].services.userspermissions.updatePermissions(cb);
|
|
|
|
});
|
2017-11-17 11:17:20 +01:00
|
|
|
};
|