Skip to content

Commit

Permalink
redirect user to last visited retreat page or home after slack sign in
Browse files Browse the repository at this point in the history
move constants to src/constants.js #8
  • Loading branch information
lourou committed Apr 22, 2018
1 parent 75e92b3 commit 8fa285c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
6 changes: 5 additions & 1 deletion helpers/airtable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var Airtable = require('airtable')
var base = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base(process.env.AIRTABLE_BASE_KEY)
const {airtableApiKey, airtableBaseKey} = require('../src/constants.js')


var base = new Airtable({apiKey: airtableApiKey}).base(airtableBaseKey)


module.exports = {
retreat: base('Retreats'),
Expand Down
4 changes: 1 addition & 3 deletions middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const request = require('request')
const clientId = process.env.SLACK_CLIENT_ID
const clientSecret = process.env.SLACK_CLIENT_SECRET
const slackRedirectUri = process.env.SLACK_REDIRECT_URI
const airtable = require('../helpers/airtable.js')
const {slackTeamName, slackClientId, slackRedirectUri, slackAuthorizeUri} = require('../src/constants.js')


function checkCode(code) {
Expand Down
2 changes: 1 addition & 1 deletion middleware/charge.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stripeSecretKey = process.env.STRIPE_SECRET_KEY ? process.env.STRIPE_SECRET_KEY : 'sk_test_5T8O9RZssCDArs5Qvab937KI'
const {stripeSecretKey} = require('../src/constants.js')
const stripe = require('stripe')(stripeSecretKey)

const price = require('./price.js')
Expand Down
10 changes: 6 additions & 4 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const price = require('../middleware/price.js')
const auth = require('../middleware/auth.js')
const charge = require('../middleware/charge.js')

const {slackTeamName, slackClientId, slackRedirectUri, slackAuthorizeUri} = require('../src/constants.js')


router.get('/', function(req, res, next) {
// find the "current" retreat and redirect to it
Expand All @@ -22,7 +24,8 @@ router.get('/login', function (req, res, next) {
// store last visited retreat
req.session.oauth_return_uri = req.query.return_uri

// @todo redirect to slack
// redirect user to slack authorize
res.redirect(slackAuthorizeUri)
})

router.get('/auth', function(req, res, next) {
Expand All @@ -34,9 +37,8 @@ router.get('/auth', function(req, res, next) {
.then(function(currentUserDetails) {
// save user details into session
req.session.currentUser = currentUserDetails
// redirect to home
res.redirect('/')
// @todo req.session.oauth_redirect_uri
// redirect to last visited retreat page or home
res.redirect('/' + (req.session.oauth_return_uri || ''))
}, function (error) {
next(error)
})
Expand Down
22 changes: 22 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require('dotenv').config()

const slackTeamName = (process.env.SLACK_TEAM_NAME || 'mangroveteam')
const slackClientId = process.env.SLACK_CLIENT_ID
const slackRedirectUri = process.env.SLACK_REDIRECT_URI
const slackAuthorizeUri = 'https://slack.com/oauth/authorize?' +
'team=' + slackTeamName +
'&scope=users:read&client_id=' + slackClientId +
'&redirect_uri=' + slackRedirectUri
const stripeSecretKey = process.env.STRIPE_SECRET_KEY ? process.env.STRIPE_SECRET_KEY : 'sk_test_5T8O9RZssCDArs5Qvab937KI'
const airtableApiKey = process.env.AIRTABLE_API_KEY
const airtableBaseKey = process.env.AIRTABLE_BASE_KEY

module.exports = {
slackTeamName,
slackClientId,
slackRedirectUri,
slackAuthorizeUri,
stripeSecretKey,
airtableApiKey,
airtableBaseKey
}

0 comments on commit 8fa285c

Please sign in to comment.