Skip to content

Commit 2b43ca0

Browse files
committed
feat: add google auth to the playground
1 parent 463c19f commit 2b43ca0

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

playground/.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Google OAuth Configuration
2+
# Get these from https://console.cloud.google.com/
3+
# 1. Create a new project or select existing
4+
# 2. Enable Google+ API or People API
5+
# 3. Go to Credentials > Create Credentials > OAuth 2.0 Client ID
6+
# 4. Set callback URL to: http://localhost:3000/api/nuxt-users/auth/google/callback
7+
8+
GOOGLE_CLIENT_ID=your_google_client_id_here
9+
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
10+
11+
# Example values for development:
12+
# GOOGLE_CLIENT_ID=123456789-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com
13+
# GOOGLE_CLIENT_SECRET=GOCSPX-abcdefghijklmnopqrstuvwxyz

playground/nuxt.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export default defineNuxtConfig({
1515
/* permissions: {
1616
admin: ['*'],
1717
}, */
18+
google: {
19+
clientId: process.env.GOOGLE_CLIENT_ID || 'demo-client-id',
20+
clientSecret: process.env.GOOGLE_CLIENT_SECRET || 'demo-client-secret',
21+
successRedirect: '/',
22+
errorRedirect: '/login?error=oauth_failed'
23+
}
1824
},
1925
passwordValidation: {
2026
minLength: 3,

playground/pages/login.vue

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const handleSubmit = (data) => {
1919
// The login composable will now handle the rememberMe flag automatically
2020
// when the server responds with user data after successful authentication
2121
}
22+
23+
const handleGoogleLogin = () => {
24+
console.log('[Nuxt Users] Starting Google OAuth flow')
25+
}
2226
</script>
2327

2428
<template>
@@ -40,6 +44,20 @@ const handleSubmit = (data) => {
4044
@error="handleError"
4145
@submit="handleSubmit"
4246
/>
47+
48+
<div class="oauth-divider">
49+
<span>or</span>
50+
</div>
51+
52+
<div class="oauth-section">
53+
<h3>OAuth Login</h3>
54+
<p>Click below to test Google OAuth (requires valid credentials in .env)</p>
55+
<NUsersGoogleLoginButton
56+
@click="handleGoogleLogin"
57+
button-text="Continue with Google"
58+
class="google-btn"
59+
/>
60+
</div>
4361
</div>
4462
</template>
4563

@@ -90,6 +108,50 @@ nav a {
90108
text-align: center;
91109
}
92110
111+
.oauth-divider {
112+
display: flex;
113+
align-items: center;
114+
text-align: center;
115+
margin: 2rem 0;
116+
}
117+
118+
.oauth-divider::before,
119+
.oauth-divider::after {
120+
content: '';
121+
flex: 1;
122+
height: 1px;
123+
background: var(--nu-color-border);
124+
}
125+
126+
.oauth-divider span {
127+
padding: 0 1rem;
128+
color: var(--nu-color-gray-500);
129+
font-size: 0.875rem;
130+
background: var(--nu-color-bg);
131+
}
132+
133+
.oauth-section {
134+
text-align: center;
135+
margin-top: 2rem;
136+
}
137+
138+
.oauth-section h3 {
139+
color: var(--nu-color-gray-700);
140+
margin-bottom: 0.5rem;
141+
font-size: 1.25rem;
142+
font-weight: 600;
143+
}
144+
145+
.oauth-section p {
146+
color: var(--nu-color-gray-500);
147+
margin-bottom: 1rem;
148+
font-size: 0.875rem;
149+
}
150+
151+
.google-btn {
152+
margin: 0 auto;
153+
}
154+
93155
/* Responsive design */
94156
@media (max-width: 48rem) {
95157
.demo-container {

0 commit comments

Comments
 (0)