๐ Social Login โ
KitchenAsty supports customer login via Google and Facebook using Passport.js OAuth strategies.
๐ข Google OAuth โ
1. ๐ง Create credentials โ
- Go to Google Cloud Console
- Create a project or select an existing one
- Navigate to APIs & Services โ Credentials
- Create an OAuth 2.0 Client ID (Web application)
- Add authorized redirect URI:
http://localhost:3000/api/auth/google/callback
2. โ๏ธ Configure environment โ
dotenv
BASE_URL=http://localhost:3000
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret3. ๐ Usage โ
Direct customers to:
GET /api/auth/googleAfter authenticating with Google, the user is redirected to the callback URL and receives a JWT token.
๐ต Facebook Login โ
1. ๐ง Create an app โ
- Go to Facebook Developers
- Create a new app and select Consumer type
- Add the Facebook Login product
- In Settings โ Basic, note your App ID and App Secret
- Add valid OAuth redirect URI:
http://localhost:3000/api/auth/facebook/callback
2. โ๏ธ Configure environment โ
dotenv
BASE_URL=http://localhost:3000
FACEBOOK_APP_ID=your-app-id
FACEBOOK_APP_SECRET=your-app-secret3. ๐ Usage โ
Direct customers to:
GET /api/auth/facebook๐ How It Works โ
- Customer clicks "Login with Google/Facebook"
- Browser redirects to the OAuth provider
- After approval, the provider redirects to
BASE_URL/api/auth/{provider}/callback - Passport.js extracts the profile and creates or updates a Customer record
- A JWT token is generated and returned via the
handleSocialCallbackcontroller - The customer is logged in with their social account
TIP
Social login routes are only registered when the corresponding environment variables are set. If GOOGLE_CLIENT_ID is not set, the /api/auth/google route will not exist.