Last active
February 1, 2018 13:04
-
-
Save Spyna/a2a435948a7443fd46d9e22334101e3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require( 'express' ); | |
var bodyParser = require( 'body-parser' ); | |
var googleAuth = require( './googleAuth.js' ); | |
var app = express(); | |
var jwt = require('./jwt.js') | |
app.use( bodyParser.json() ); | |
app.use( bodyParser.urlencoded( { extended: false } ) ); | |
app.post( '/auth/token', ( req, res ) => { | |
try { | |
var login = req.body; | |
googleAuth.getGoogleUser( login.code ) | |
.then( response => { | |
var content = { | |
token: jwt.createToken( response ), | |
user: response | |
} | |
return content | |
} ) | |
.then( credentials => { | |
res.setHeader( 'Content-Type', 'application/json' ); | |
res.end( JSON.stringify( credentials ) ); | |
} ) | |
.catch( e => { | |
console.log( e ) | |
throw new Error( e ) | |
} ) | |
} catch ( error ) { | |
res.sendStatus( 500 ).end( JSON.stringify( { error: "Internal server error" } ) ) | |
return console.error( error ) | |
} | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment