Cara menambahkan tombol Login/Register dengan Google (OAuth) ke proyek backend Flask dan frontend React Anda, berikut langkah-langkah lengkapnya:
๐ ️ Bagian 1: Daftar dan Konfigurasi Google OAuth
1. Masuk ke Google Developer Console
๐ https://console.developers.google.com/
2. Buat Project Baru
-
Klik
Select a project > New Project
-
Isi nama proyek, klik
Create
3. Aktifkan Google OAuth API
-
Di sidebar:
APIs & Services > Library
-
Cari "Google Identity Services" atau "OAuth 2.0" dan klik Enable
4. Buat OAuth 2.0 Client ID
-
Menu:
APIs & Services > Credentials
-
Klik
+ CREATE CREDENTIALS > OAuth client ID
-
Pilih:
-
Application type:
Web Application
-
Name:
Web Client for E-Book Store
-
Authorized JavaScript origins:
-
http://localhost:3000
(React frontend)
-
-
Authorized redirect URIs:
-
http://localhost:5000/auth/google/callback
(Flask backend route)
-
-
-
Simpan
client_id
danclient_secret
⚙️ Bagian 2: Backend Flask Setup (Google OAuth)
1. Install dependency
2. Tambahkan ke Flask App
3. Buat Callback Route
๐ป Bagian 3: React Frontend Setup
1. Install Library
2. Setup Google OAuth Provider di index.jsx
3. Buat Tombol Login
๐งช Testing
-
Jalankan Flask backend (
localhost:5000
) -
Jalankan React frontend (
localhost:3000
) -
Klik tombol Google login → pastikan akun Anda muncul di database → token tersimpan di localStorage
No comments:
Post a Comment