Google Login in Express with PassportJS & JWT
The article provides a guide on implementing Google Authentication in an Express.js application using various technologies. It outlines the necessary steps, including setting up Google OAuth credentials and configuring PassportJS for authentication. Additionally, it details the required changes to the user model and the creation of routes for handling Google login.
- ▪The implementation uses TypeScript, Express.js, Mongoose, Passport.js, and JWT for authentication.
- ▪Users must create OAuth credentials in the Google Cloud Console to obtain a Client ID and Client Secret.
- ▪The user model needs to include fields for refreshToken and googleId, and password login should be made optional.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 2071314) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } NHero Posted on May 23 • Originally published at nhero.me Google Login in Express with PassportJS & JWT #webdev #backend #express #passportjs In this blog, we will implement Google Authentication in an Express.js app using: TypeScript Express.js Mongoose Passport.js JWT Authentication Project Structure └── src/ ├── config/ ├── controllers/ ├── middlewares/ ├── models/ ├── routes/ ├── utils/ ├── app.ts └── index.ts ├── .env ├── package.json └── tsconfig.json Enter fullscreen mode…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).