File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ export default defineNuxtModule<RuntimeModuleOptions>({
143143 }
144144
145145 return combinedWhitelist
146- } ) ( )
146+ } ) ( ) ,
147147 permissions : runtimeConfigOptions . auth ?. permissions || defaultOptions . auth . permissions
148148 } ,
149149 apiBasePath : runtimeConfigOptions . apiBasePath || defaultOptions . apiBasePath
Original file line number Diff line number Diff line change 1+ import { useDb } from './db'
2+ import type { ModuleOptions } from 'nuxt-users/utils'
3+
4+ export const addGoogleOauthFields = async ( options : ModuleOptions ) => {
5+ const connectorName = options . connector ! . name
6+ const db = await useDb ( options )
7+ const tableName = options . tables . users
8+
9+ console . log ( `[Nuxt Users] DB:Add Google OAuth fields to ${ connectorName } Users Table in ${ tableName } ...` )
10+
11+ if ( connectorName === 'sqlite' || connectorName === 'mysql' || connectorName === 'postgresql' ) {
12+ // Try to add the columns, ignore errors if they already exist
13+ try {
14+ await db . sql `ALTER TABLE {${ tableName } } ADD COLUMN google_id TEXT UNIQUE`
15+ console . log ( '[Nuxt Users] Added google_id column ✅' )
16+ }
17+ catch ( error ) {
18+ // Column might already exist, ignore the error
19+ console . log ( '[Nuxt Users] google_id column might already exist' )
20+ }
21+
22+ try {
23+ await db . sql `ALTER TABLE {${ tableName } } ADD COLUMN profile_picture TEXT`
24+ console . log ( '[Nuxt Users] Added profile_picture column ✅' )
25+ }
26+ catch ( error ) {
27+ // Column might already exist, ignore the error
28+ console . log ( '[Nuxt Users] profile_picture column might already exist' )
29+ }
30+ }
31+
32+ console . log ( `[Nuxt Users] DB:Add Google OAuth fields to ${ connectorName } Users Table ✅` )
33+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { createPersonalAccessTokensTable } from './create-personal-access-tokens
55import { createPasswordResetTokensTable } from './create-password-reset-tokens-table'
66import { createMigrationsTable } from './create-migrations-table'
77import { addActiveToUsers } from './add-active-to-users'
8+ import { addGoogleOauthFields } from './add-google-oauth-fields'
89
910interface Migration {
1011 name : string
@@ -31,6 +32,10 @@ const migrations: Migration[] = [
3132 {
3233 name : 'add_active_to_users' ,
3334 run : addActiveToUsers
35+ } ,
36+ {
37+ name : 'add_google_oauth_fields' ,
38+ run : addGoogleOauthFields
3439 }
3540]
3641
You can’t perform that action at this time.
0 commit comments