Loading...
Loading...
Loading...
วิธีเพิ่ม Google OAuth provider — สร้าง credentials, เพิ่ม provider, sign-in flow
ขั้นตอนการเพิ่ม Google OAuth provider — สร้าง credentials, config, sign-in button
# ขั้นตอน:
# 1. ไปที่ https://console.cloud.google.com/apis/credentials
# 2. Create Credentials → OAuth client ID
# 3. Application type: Web application
# 4. Authorized redirect URIs:
# - http://localhost:3000/api/auth/callback/google (dev)
# - https://yourdomain.com/api/auth/callback/google (prod)
# 5. Copy Client ID และ Client Secret# .env
AUTH_GOOGLE_ID="your-google-client-id.apps.googleusercontent.com"
AUTH_GOOGLE_SECRET="your-google-client-secret"import Google from 'next-auth/providers/google';
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
Google,
Credentials({ ... }),
],
// ... callbacks
});// Server Action
import { signIn } from '@/lib/auth/auth';
export async function signInWithGoogle() {
'use server';
await signIn('google', { redirectTo: '/features/next-auth' });
}
// Client Component
import { signIn } from 'next-auth/react';
<Button onClick={() => signIn('google', { redirectTo: '/features/next-auth' })}>
Sign in with Google
</Button>