Skip to content

Commit

Permalink
bugfix(social auth): redirect to frontend on successful signin
Browse files Browse the repository at this point in the history
if a user has successfully signed in, generate a token and redirect the user to the front end

[Finishes #165380523]
  • Loading branch information
codinger41 committed Apr 16, 2019
1 parent 1d70543 commit f929def
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions routes/v1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import jwt from 'jsonwebtoken';
import UserController from '../controllers/user';
import passport from '../auth/passport';
import ProfileController from '../controllers/profile';
Expand Down Expand Up @@ -121,7 +122,14 @@ apiRoutes.get('/auth/google/callback',
'google', { failureRedirect: '/login' }
),
(req, res) => {
res.redirect('/');
const { user } = req;
user.password = undefined;
user.verified = undefined;
user.verificationId = undefined;
user.passwordResetToken = undefined;
user.passwordResetTokenExpires = undefined;
const token = jwt.sign({ ...req.user }, process.env.JWT_SECRET);
res.redirect(`${process.env.HOST_URL_FRONTEND}/social/callback?token=${token}`);
});

apiRoutes.get('/auth/facebook',
Expand All @@ -136,7 +144,14 @@ apiRoutes.get('/auth/facebook/callback',
'facebook', { failureRedirect: '/login' }
),
(req, res) => {
res.redirect('/');
const { user } = req;
user.password = undefined;
user.verified = undefined;
user.verificationId = undefined;
user.passwordResetToken = undefined;
user.passwordResetTokenExpires = undefined;
const token = jwt.sign({ ...req.user }, process.env.JWT_SECRET);
res.redirect(`${process.env.HOST_URL_FRONTEND}/social/callback?token=${token}`);
});

apiRoutes.post(
Expand Down

0 comments on commit f929def

Please sign in to comment.