Skip to content

Commit

Permalink
feat: authentication callback
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jun 14, 2019
1 parent e9d466a commit 8f18892
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/routes/ecom/auth-callback.js
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
'use strict'

// log on files
const logger = require('console-files')

module.exports = appSdk => {
return (req, res) => {
// E-Com Plus Store ID from request header
const storeId = parseInt(req.get('x-store-id'), 10)

// handle callback with E-Com Plus app SDK
// https://github.com/ecomclub/ecomplus-app-sdk
appSdk.handleCallback(storeId, req.body)

.then(({ isNew, authenticationId }) => {
// authentication tokens were updated
res.status(204)
res.end()
})

.catch(err => {
if (typeof err.code === 'string' && !err.code.startsWith('SQLITE_CONSTRAINT')) {
// debug SQLite errors
logger.error(err)
}
res.status(500)
let { message } = err
res.send({
error: 'auth_callback_error',
message
})
})
}
}

0 comments on commit 8f18892

Please sign in to comment.