SHARE
TWEET

Untitled

a guest Feb 18th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.get('/users/google', passport.authenticate('google', {
  2. scope : ['email']
  3.  }));
  4.  
  5. router.get('/users/google/redirect', function (req, res, next) {
  6.    console.log(req.isAuthenticated())
  7.    console.log(req.session);
  8.    passport.authenticate('google', function(err, user, info) {
  9.    if (err) { return next(err); }
  10.    req.logIn(user, function(err) {
  11.     if (err) { return next(err); }
  12.     return res.redirect('http://localhost:4200/');
  13.   });
  14. })(req, res, next);
  15.  
  16. });
  17.  
  18.  router.get('/logout', loggedIn,function(req, res){
  19.     console.log(req.isAuthenticated());
  20.     req.logout();
  21.     return res.redirect('http://localhost:4200/register');
  22.  });
  23.  
  24. function loggedIn(req, res, next) {
  25.  
  26.  if (req.user) {
  27.    console.log('LOGED');
  28.    next();
  29.  } else {
  30.    res.redirect('/login');
  31.  }
  32. }
  33.    
  34. OnNavigate() {
  35.    console.log('aaaa')
  36.    window.open("http://localhost:3000/users/google", "_blank");
  37.  }
  38.    
  39. logOut() {
  40. this.userService.logOut().subscribe();
  41. }
  42.  
  43.  
  44. logOut(): Observable<any> {
  45.     console.log('From uSEr');
  46.     return this.apiService.get('/logout')
  47.         .pipe(map(
  48.             data => {
  49.                 console.log(data);
  50.                 return data;
  51.             }
  52.         ));
  53. }
  54.  
  55.  get(path: string, params: HttpParams = new HttpParams()) : Observable<any>
  56. {
  57.   console.log(`${environment.api_url}${path}`);
  58.   return this.http.get(
  59.     `${environment.api_url}${path}`, { params }
  60.   );
  61.  
  62. }
  63.    
  64. <a href="http://localhost:3000/logout"class="nav-item nav-link">
  65.    
  66. var app = express();
  67. app.use(cors());
  68.  
  69.   // Normal express config defaults
  70. app.use(require('morgan')('dev'));
  71. app.use(bodyParser.json());
  72. app.use(bodyParser.urlencoded({ extended: false }));
  73.  
  74.  app.use(require('method-override')());
  75.  app.use(express.static(__dirname + '/public')) ;
  76.  //app.use(cookieParser(sessionOpts.secret))
  77.   app.use(session(sessionOpts))
  78.   app.use(passport.initialize())
  79.   app.use(passport.session())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top