Skip to content

Commit 16aefa9

Browse files
committed
fix: add api endpoints to public endpoints
1 parent 2b43ca0 commit 16aefa9

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

src/module.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ export default defineNuxtModule<RuntimeModuleOptions>({
6868
...runtimeConfigOptions.auth,
6969
whitelist: (() => {
7070
const combinedWhitelist = [...(defaultOptions.auth?.whitelist || []), ...(runtimeConfigOptions.auth?.whitelist || [])]
71+
const apiBasePath = runtimeConfigOptions.apiBasePath || defaultOptions.apiBasePath
72+
7173
// Auto-whitelist related endpoints if /register is whitelisted
7274
if (combinedWhitelist.includes('/register')) {
73-
const apiBasePath = runtimeConfigOptions.apiBasePath || defaultOptions.apiBasePath
7475
const registrationEndpoints = [
7576
'/confirm-email', // Page route for email confirmation
7677
`${apiBasePath}/register`, // API endpoint for registration
@@ -83,8 +84,23 @@ export default defineNuxtModule<RuntimeModuleOptions>({
8384
}
8485
})
8586
}
87+
88+
// Auto-whitelist Google OAuth endpoints if Google OAuth is configured
89+
if (runtimeConfigOptions.auth?.google) {
90+
const googleOAuthEndpoints = [
91+
`${apiBasePath}/auth/google/redirect`,
92+
`${apiBasePath}/auth/google/callback`
93+
]
94+
95+
googleOAuthEndpoints.forEach((endpoint) => {
96+
if (!combinedWhitelist.includes(endpoint)) {
97+
combinedWhitelist.push(endpoint)
98+
}
99+
})
100+
}
101+
86102
return combinedWhitelist
87-
})(),
103+
})()
88104
},
89105
}
90106

@@ -95,9 +111,10 @@ export default defineNuxtModule<RuntimeModuleOptions>({
95111
auth: {
96112
whitelist: (() => {
97113
const combinedWhitelist = [...(defaultOptions.auth?.whitelist || []), ...(runtimeConfigOptions.auth?.whitelist || [])]
114+
const apiBasePath = runtimeConfigOptions.apiBasePath || defaultOptions.apiBasePath
115+
98116
// Auto-whitelist related endpoints if /register is whitelisted
99117
if (combinedWhitelist.includes('/register')) {
100-
const apiBasePath = runtimeConfigOptions.apiBasePath || defaultOptions.apiBasePath
101118
const registrationEndpoints = [
102119
'/confirm-email', // Page route for email confirmation
103120
`${apiBasePath}/register`, // API endpoint for registration
@@ -110,8 +127,23 @@ export default defineNuxtModule<RuntimeModuleOptions>({
110127
}
111128
})
112129
}
130+
131+
// Auto-whitelist Google OAuth endpoints if Google OAuth is configured
132+
if (runtimeConfigOptions.auth?.google) {
133+
const googleOAuthEndpoints = [
134+
`${apiBasePath}/auth/google/redirect`,
135+
`${apiBasePath}/auth/google/callback`
136+
]
137+
138+
googleOAuthEndpoints.forEach((endpoint) => {
139+
if (!combinedWhitelist.includes(endpoint)) {
140+
combinedWhitelist.push(endpoint)
141+
}
142+
})
143+
}
144+
113145
return combinedWhitelist
114-
})(),
146+
})()
115147
permissions: runtimeConfigOptions.auth?.permissions || defaultOptions.auth.permissions
116148
},
117149
apiBasePath: runtimeConfigOptions.apiBasePath || defaultOptions.apiBasePath

src/runtime/assets/nuxt-users.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,25 @@
182182
margin: 0;
183183
}
184184

185+
/* Google OAuth Button */
186+
.n-users-google-btn {
187+
display: inline-flex;
188+
align-items: center;
189+
justify-content: center;
190+
gap: 8px;
191+
}
192+
193+
.n-users-google-logo {
194+
flex-shrink: 0;
195+
}
196+
185197
/* Buttons */
186198
.n-users-btn,
187199
.n-users-submit-btn,
188200
.n-users-cancel-btn,
189201
.n-users-edit-btn,
190-
.n-users-delete-btn {
202+
.n-users-delete-btn,
203+
.n-users-google-btn {
191204
padding: 0.5rem 1rem;
192205
border: none;
193206
border-radius: 0.25rem;

src/runtime/server/api/nuxt-users/auth/google/callback.get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
getGoogleUserFromCode,
77
findOrCreateGoogleUser,
88
createAuthTokenForUser
9-
} from '../../../utils/google-oauth'
9+
} from '../../../../utils/google-oauth'
1010

1111
export default defineEventHandler(async (event) => {
1212
const { nuxtUsers } = useRuntimeConfig()
@@ -69,7 +69,7 @@ export default defineEventHandler(async (event) => {
6969
setCookie(event, 'auth_token', token, cookieOptions)
7070

7171
// Update last login time
72-
const { useDb } = await import('../../../utils/db')
72+
const { useDb } = await import('../../../../utils/db')
7373
const db = await useDb(options)
7474
await db.sql`
7575
UPDATE {${options.tables.users}}

src/runtime/server/api/nuxt-users/auth/google/redirect.get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineEventHandler, sendRedirect, createError } from 'h3'
22
import type { ModuleOptions } from 'nuxt-users/utils'
33
import { useRuntimeConfig } from '#imports'
4-
import { createGoogleOAuth2Client, getGoogleAuthUrl } from '../../../utils/google-oauth'
4+
import { createGoogleOAuth2Client, getGoogleAuthUrl } from '../../../../utils/google-oauth'
55

66
export default defineEventHandler(async (event) => {
77
const { nuxtUsers } = useRuntimeConfig()

0 commit comments

Comments
 (0)