Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

const jwt = require('jsonwebtoken');
const models = require('../models');
const Strategy = require('passport-local');
function generateToken(req, res, next) {
res.cookie('token',
jwt.sign({ id: req.user.id }, process.env.SECRET),
{
maxAge: 86400000,
httpOnly: true,
@captDaylight
captDaylight / auth.js
Last active November 22, 2016 20:17
Generating JWT for my current project
const jwt = require('jsonwebtoken');
const models = require('../models');
const Strategy = require('passport-local');
function generateToken(req, res, next) {
res.cookie('token',
jwt.sign({ id: req.user.id }, process.env.SECRET),
{
maxAge: 86400000,
httpOnly: true,
if (!process.env.token) {
process.exit(1);
}
const Botkit = require('botkit');
const controller = Botkit.slackbot({
debug: true,
});
} else {
const gameResults = playerIDs.map((id) => `<@${id}> played ${players[id].played}`);
bot.reply(message, gameResults.join(' & '));
// reset the game data
channels.save({ id: updateData.id }, (err) => {
if (err) throw err;
});
}
channels.get(channel, (err, data) => {
...
if (onlyOnePlayed) {
channels.save(updateData, (err) => {
if (err) throw err;
bot.reply(message, `<@${user}> has played!`);
});
if (convo.status === 'completed') {
const prc = convo.extractResponse('rockPaperScissors');
channels.get(channel, (err, data) => {
if (err) throw err;
const updateData = data;
updateData.players[user].played = prc;
const { players } = updateData;
convo.on('end', (convo) => {
if (convo.status === 'completed') {
// conversation completed correctly
const prc = convo.extractResponse('rockPaperScissors');
} else {
// this happens if the conversation ended prematurely for some reason
bot.reply(message, 'OK, nevermind!');
}
});
function privateConvo(bot, message) {
const { user, channel } = message;
return (err, convo) => {
if (err) throw err;
convo.ask(...);
// on end, update game data and broadcast info
convo.on('end', callback);
return (err, convo) => {
convo.ask('Do you want to play `paper`, `rock`, or `scissors`?', [
{
pattern: 'paper|rock|scissors',
callback(response, convo) {
// since no further messages are queued after this,
// the conversation will end naturally with status === ‘completed’
convo.next();
},
}, {
function privateConvo(bot, message) {
return (err, convo) => {};
}
...
bot.startPrivateConversation(message, privateConvo(bot, message));