@@ -136,18 +136,45 @@ app.use(assetRoutes);
136136
137137app . use ( '/' , embedRoutes ) ;
138138app . get ( '/auth/github' , passport . authenticate ( 'github' ) ) ;
139- app . get ( '/auth/github/callback' , passport . authenticate ( 'github' , { failureRedirect : '/login' } ) , ( req , res ) => {
140- res . redirect ( '/' ) ;
139+ app . get ( '/auth/github/callback' , ( req , res , next ) => {
140+ passport . authenticate ( 'github' , { failureRedirect : '/login' } , ( err , user ) => {
141+ if ( err ) {
142+ // use query string param to show error;
143+ res . redirect ( '/account' ) ;
144+ return ;
145+ }
146+
147+ req . logIn ( user , ( loginErr ) => {
148+ if ( loginErr ) {
149+ next ( loginErr ) ;
150+ return ;
151+ }
152+ res . redirect ( '/' ) ;
153+ } ) ;
154+ } ) ( req , res , next ) ;
141155} ) ;
142156
143157app . get ( '/auth/google' , passport . authenticate ( 'google' ) ) ;
144- app . get ( '/auth/google/callback' , passport . authenticate ( 'google' , { failureRedirect : '/login' } ) , ( req , res ) => {
145- res . redirect ( '/' ) ;
158+ app . get ( '/auth/google/callback' , ( req , res , next ) => {
159+ passport . authenticate ( 'google' , { failureRedirect : '/login' } , ( err , user ) => {
160+ if ( err ) {
161+ // use query string param to show error;
162+ res . redirect ( '/account' ) ;
163+ return ;
164+ }
165+
166+ req . logIn ( user , ( loginErr ) => {
167+ if ( loginErr ) {
168+ next ( loginErr ) ;
169+ return ;
170+ }
171+ res . redirect ( '/' ) ;
172+ } ) ;
173+ } ) ( req , res , next ) ;
146174} ) ;
147175
148176// configure passport
149177require ( './config/passport' ) ;
150- // const passportConfig = require('./config/passport');
151178
152179// Connect to MongoDB
153180mongoose . Promise = global . Promise ;
@@ -190,7 +217,7 @@ app.get('*', (req, res) => {
190217// start app
191218app . listen ( process . env . PORT , ( error ) => {
192219 if ( ! error ) {
193- console . log ( `p5js web editor is running on port: ${ process . env . PORT } !` ) ; // eslint-disable-line
220+ console . log ( `p5.js Web Editor is running on port: ${ process . env . PORT } !` ) ; // eslint-disable-line
194221 }
195222} ) ;
196223
0 commit comments