Skip to content

Commit 3ed5bcc

Browse files
committed
chore: fix lint errors
1 parent 0e8e3d4 commit 3ed5bcc

File tree

13 files changed

+135
-127
lines changed

13 files changed

+135
-127
lines changed

playground/pages/login.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ const dismissError = () => {
6161
<h2>Login Component Demo</h2>
6262
</div>
6363

64-
<div v-if="oauthError" class="error-banner">
64+
<div
65+
v-if="oauthError"
66+
class="error-banner"
67+
>
6568
<div class="error-content">
6669
<span class="error-icon">⚠️</span>
6770
<span class="error-message">{{ oauthError }}</span>
68-
<button class="error-dismiss" @click="dismissError">✕</button>
71+
<button
72+
class="error-dismiss"
73+
@click="dismissError"
74+
>
75+
76+
</button>
6977
</div>
7078
</div>
7179

@@ -74,18 +82,18 @@ const dismissError = () => {
7482
@error="handleError"
7583
@submit="handleSubmit"
7684
/>
77-
85+
7886
<div class="oauth-divider">
7987
<span>or</span>
8088
</div>
81-
89+
8290
<div class="oauth-section">
8391
<h3>OAuth Login</h3>
8492
<p>Click below to test Google OAuth (requires valid credentials in .env)</p>
85-
<NUsersGoogleLoginButton
86-
@click="handleGoogleLogin"
93+
<NUsersGoogleLoginButton
8794
button-text="Continue with Google"
8895
class="google-btn"
96+
@click="handleGoogleLogin"
8997
/>
9098
</div>
9199
</div>

src/cli/add-google-oauth-fields.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export default defineCommand({
2222
// Check if columns already exist
2323
const tableInfo = await db.sql`PRAGMA table_info(${tableName})` as { rows: Array<{ name: string }> }
2424
const columnNames = tableInfo.rows.map(row => row.name)
25-
25+
2626
if (!columnNames.includes('google_id')) {
2727
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN google_id TEXT`
2828
console.log('[Nuxt Users] Added google_id column to SQLite users table ✅')
2929
}
30-
30+
3131
if (!columnNames.includes('profile_picture')) {
3232
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN profile_picture TEXT`
3333
console.log('[Nuxt Users] Added profile_picture column to SQLite users table ✅')
@@ -38,7 +38,7 @@ export default defineCommand({
3838
console.log('[Nuxt Users] Added last_login_at column to SQLite users table ✅')
3939
}
4040
}
41-
41+
4242
if (connectorName === 'mysql') {
4343
// Check if columns exist
4444
const checkColumns = await db.sql`
@@ -48,20 +48,20 @@ export default defineCommand({
4848
AND TABLE_NAME = ${tableName}
4949
AND COLUMN_NAME IN ('google_id', 'profile_picture')
5050
` as { rows: Array<{ COLUMN_NAME: string }> }
51-
51+
5252
const existingColumns = checkColumns.rows.map(row => row.COLUMN_NAME)
53-
53+
5454
if (!existingColumns.includes('google_id')) {
5555
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN google_id VARCHAR(255) UNIQUE`
5656
console.log('[Nuxt Users] Added google_id column to MySQL users table ✅')
5757
}
58-
58+
5959
if (!existingColumns.includes('profile_picture')) {
6060
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN profile_picture TEXT`
6161
console.log('[Nuxt Users] Added profile_picture column to MySQL users table ✅')
6262
}
6363
}
64-
64+
6565
if (connectorName === 'postgresql') {
6666
// Check if columns exist
6767
const checkColumns = await db.sql`
@@ -70,25 +70,25 @@ export default defineCommand({
7070
WHERE table_name = ${tableName}
7171
AND column_name IN ('google_id', 'profile_picture')
7272
` as { rows: Array<{ column_name: string }> }
73-
73+
7474
const existingColumns = checkColumns.rows.map(row => row.column_name)
75-
75+
7676
if (!existingColumns.includes('google_id')) {
7777
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN google_id VARCHAR(255) UNIQUE`
7878
console.log('[Nuxt Users] Added google_id column to PostgreSQL users table ✅')
7979
}
80-
80+
8181
if (!existingColumns.includes('profile_picture')) {
8282
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN profile_picture TEXT`
8383
console.log('[Nuxt Users] Added profile_picture column to PostgreSQL users table ✅')
8484
}
8585
}
86-
86+
8787
console.log('[Nuxt Users] Google OAuth fields migration completed successfully! ✅')
88-
89-
} catch (error) {
88+
}
89+
catch (error) {
9090
console.error('[Nuxt Users] DB:Migration Error:', error)
9191
process.exit(1)
9292
}
9393
}
94-
})
94+
})

src/runtime/components/NUsersGoogleLoginButton.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,22 @@ const { apiBasePath } = nuxtUsers as ModuleOptions
4242
const isLoading = ref(false)
4343
4444
// Compute redirect URL
45-
const redirectEndpoint = computed(() =>
45+
const redirectEndpoint = computed(() =>
4646
props.redirectEndpoint || `${apiBasePath}/auth/google/redirect`
4747
)
4848
4949
const handleGoogleLogin = async () => {
5050
isLoading.value = true
5151
emit('click')
52-
52+
5353
try {
5454
// Navigate to Google OAuth redirect endpoint
5555
await navigateTo(redirectEndpoint.value, { external: true })
56-
} catch (error) {
56+
}
57+
catch (error) {
5758
console.error('[Nuxt Users] Google OAuth redirect failed:', error)
58-
} finally {
59+
}
60+
finally {
5961
isLoading.value = false
6062
}
6163
}
@@ -65,7 +67,7 @@ const handleGoogleLogin = async () => {
6567
<button
6668
type="button"
6769
class="n-users-google-btn"
68-
:class="[{ 'loading': isLoading }, props.class]"
70+
:class="[{ loading: isLoading }, props.class]"
6971
:disabled="isLoading"
7072
@click="handleGoogleLogin"
7173
>
@@ -74,7 +76,7 @@ const handleGoogleLogin = async () => {
7476
v-if="isLoading"
7577
class="n-users-loading-spinner"
7678
/>
77-
79+
7880
<!-- Google logo SVG -->
7981
<svg
8082
v-if="showLogo && !isLoading"
@@ -108,4 +110,4 @@ const handleGoogleLogin = async () => {
108110
</button>
109111
</template>
110112

111-
<!-- CSS removed - now consolidated in nuxt-users.css -->
113+
<!-- CSS removed - now consolidated in nuxt-users.css -->

src/runtime/composables/useAuthentication.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,23 @@ export const useAuthentication = () => {
5858
const fetchUser = async (useSSR = false) => {
5959
try {
6060
let userData: UserWithoutPassword | null = null
61-
61+
6262
if (useSSR) {
6363
// Use useFetch for SSR - properly handles cookies
6464
const { data, error } = await useFetch<{ user: UserWithoutPassword }>(`${apiBasePath}/me`, {
6565
server: true,
6666
lazy: false
6767
})
68-
68+
6969
if (error.value) {
7070
throw new Error(error.value.message || 'Failed to fetch user')
7171
}
72-
72+
7373
userData = data.value?.user || null
74-
} else {
74+
}
75+
else {
7576
// Use $fetch for client-only requests
76-
const response = await $fetch<{ user: UserWithoutPassword }>(`${apiBasePath}/me`, {
77+
const response = await $fetch<{ user: UserWithoutPassword }>(`${apiBasePath}/me`, {
7778
method: 'GET'
7879
})
7980
userData = response.user

src/runtime/middleware/authorization.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
2828
}
2929

3030
const { isAuthenticated, user, fetchUser } = useAuthentication()
31-
31+
3232
// If not authenticated but oauth_success flag is present, fetch user using SSR
3333
if (!isAuthenticated.value && to.query?.oauth_success === 'true') {
3434
try {
@@ -38,7 +38,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
3838
console.error('[Nuxt Users] Failed to fetch user after OAuth:', error)
3939
}
4040
}
41-
41+
4242
if (!isAuthenticated.value) {
4343
console.log(`[Nuxt Users] client.middleware.auth.global: Unauthenticated ${to.path}, redirecting to /login`)
4444
return navigateTo('/login')

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineEventHandler, sendRedirect, createError } from 'h3'
1+
import { defineEventHandler, sendRedirect, createError, type H3Event } from 'h3'
22
import type { ModuleOptions } from 'nuxt-users/utils'
33
import { useRuntimeConfig } from '#imports'
44
import { createGoogleOAuth2Client, getGoogleAuthUrl } from '../../../../utils/google-oauth'
@@ -34,8 +34,8 @@ export default defineEventHandler(async (event) => {
3434

3535
// Redirect to Google OAuth
3636
return sendRedirect(event, authUrl)
37-
38-
} catch (error) {
37+
}
38+
catch (error) {
3939
console.error('[Nuxt Users] Google OAuth redirect error:', error)
4040
throw createError({
4141
statusCode: 500,
@@ -44,10 +44,9 @@ export default defineEventHandler(async (event) => {
4444
}
4545
})
4646

47-
// Helper function to get request URL
48-
function getRequestURL(event: any) {
47+
const getRequestURL = (event: H3Event) => {
4948
const headers = event.node.req.headers
5049
const host = headers.host || headers[':authority']
51-
const protocol = headers['x-forwarded-proto'] || (event.node.req.socket?.encrypted ? 'https' : 'http')
50+
const protocol = headers['x-forwarded-proto']
5251
return new URL(`${protocol}://${host}`)
53-
}
52+
}

src/runtime/server/utils/add-google-oauth-fields.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ export const addGoogleOauthFields = async (options: ModuleOptions) => {
1616
}
1717
catch (error) {
1818
// Column might already exist, ignore the error
19-
console.log('[Nuxt Users] google_id column might already exist')
19+
console.error('[Nuxt Users] google_id column might already exist', error)
2020
}
21-
21+
2222
try {
2323
await db.sql`ALTER TABLE {${tableName}} ADD COLUMN profile_picture TEXT`
2424
console.log('[Nuxt Users] Added profile_picture column ✅')
2525
}
2626
catch (error) {
2727
// Column might already exist, ignore the error
28-
console.log('[Nuxt Users] profile_picture column might already exist')
28+
console.error('[Nuxt Users] profile_picture column might already exist', error)
2929
}
3030
}
3131

src/runtime/server/utils/google-oauth.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function createGoogleOAuth2Client(options: GoogleOAuthOptions, callbackUr
2828
*/
2929
export function getGoogleAuthUrl(oauth2Client: OAuth2Client, options: GoogleOAuthOptions): string {
3030
const scopes = options.scopes || ['openid', 'profile', 'email']
31-
31+
3232
return oauth2Client.generateAuthUrl({
3333
access_type: 'offline',
3434
scope: scopes,
@@ -82,7 +82,7 @@ export async function generateSecurePassword(): Promise<string> {
8282
* Find or create user from Google OAuth data
8383
*/
8484
export async function findOrCreateGoogleUser(
85-
googleUser: GoogleUserInfo,
85+
googleUser: GoogleUserInfo,
8686
moduleOptions: ModuleOptions
8787
): Promise<User | null> {
8888
const db = await useDb(moduleOptions)
@@ -97,7 +97,7 @@ export async function findOrCreateGoogleUser(
9797

9898
if (userResult.rows.length > 0) {
9999
const user = userResult.rows[0]
100-
100+
101101
// Update profile picture if it has changed
102102
if (user.profile_picture !== googleUser.picture) {
103103
await db.sql`
@@ -107,7 +107,7 @@ export async function findOrCreateGoogleUser(
107107
`
108108
user.profile_picture = googleUser.picture
109109
}
110-
110+
111111
return user
112112
}
113113

@@ -127,7 +127,7 @@ export async function findOrCreateGoogleUser(
127127
updated_at = CURRENT_TIMESTAMP
128128
WHERE id = ${user.id}
129129
`
130-
130+
131131
user.google_id = googleUser.id
132132
user.profile_picture = googleUser.picture
133133
return user
@@ -140,8 +140,8 @@ export async function findOrCreateGoogleUser(
140140

141141
// Create new user
142142
const securePassword = await generateSecurePassword()
143-
144-
const insertResult = await db.sql`
143+
144+
await db.sql`
145145
INSERT INTO {${usersTable}} (
146146
email, name, password, role, google_id, profile_picture,
147147
active, created_at, updated_at
@@ -171,13 +171,13 @@ export async function findOrCreateGoogleUser(
171171
* Create authentication token for user (reusing existing logic)
172172
*/
173173
export async function createAuthTokenForUser(
174-
user: User,
174+
user: User,
175175
moduleOptions: ModuleOptions,
176176
rememberMe = false
177177
): Promise<string> {
178178
const db = await useDb(moduleOptions)
179179
const personalAccessTokensTable = moduleOptions.tables.personalAccessTokens
180-
180+
181181
const token = crypto.randomBytes(64).toString('hex')
182182
const tokenName = 'oauth_auth_token'
183183

@@ -186,7 +186,8 @@ export async function createAuthTokenForUser(
186186
if (rememberMe) {
187187
const longTermDays = moduleOptions.auth.rememberMeExpiration || 30
188188
expiresAt.setDate(expiresAt.getDate() + longTermDays)
189-
} else {
189+
}
190+
else {
190191
expiresAt.setMinutes(expiresAt.getMinutes() + moduleOptions.auth.tokenExpiration)
191192
}
192193

@@ -206,4 +207,4 @@ export async function createAuthTokenForUser(
206207
`
207208

208209
return token
209-
}
210+
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface GoogleOAuthOptions {
2121
*/
2222
clientId: string
2323
/**
24-
* Google OAuth client secret from Google Cloud Console
24+
* Google OAuth client secret from Google Cloud Console
2525
*/
2626
clientSecret: string
2727
/**

0 commit comments

Comments
 (0)