Back to articles
How to Implement Google OAuth 2.0 in Next.js with NestJS
How-ToTools

How to Implement Google OAuth 2.0 in Next.js with NestJS

via Dev.toMarwan Zaky

Step by step on how to implement Google OAuth in Next.js with NestJS. Demo example: https://mamolio.vercel.app/signin Demo code: https://github.com/marwanzaky/mern-ecommerce 1. Create Google OAuth Credentials Go to: http://console.cloud.google.com Create a project Go to: APIs & Services > Credentials > Create credentials > Create OAuth client ID Choose: App type: Web application Add: Authorized redirect URI http://localhost:3001/auth/google/callback Copy: CLIENT_ID CLIENT_SECRET 2. Backend NestJS Install dependencies: npm install passport @types/passport @nestjs/passport passport-google-oauth20 @types/passport-google-oauth20 Create Google Strategy import { Injectable } from " @nestjs/common " ; import { PassportStrategy } from " @nestjs/passport " ; import { Strategy , VerifyCallback } from " passport-google-oauth20 " ; @ Injectable () export class GoogleStrategy extends PassportStrategy ( Strategy , " google " ) { constructor () { super ({ clientID : process . env . GOOGLE_CLIENT_ID !

Continue reading on Dev.to

Opens in a new tab

Read Full Article
6 views

Related Articles