dmb
dmb
DTDrizzle Team
Created by dmb on 4/9/2025 in #help
Running into URL constructor issues when combined with Auth0's NextJS package
Hey all; I'm currently running into some really annoying issues when trying to insert a user into my database once they have been authenticated by Auth0. I'm attempting to do this in the beforeSessionSaved handler within the Auth0Client. I've opened a ticket for them to take a look at but I wondered if there's anything I can do on the Drizzle side? The error I'm seeing is "TypeError: URL is not a constructor" and this only happens when using Drizzle from within the callback.
export const db = drizzle(process.env.DATABASE_URL!, { schema, mode: 'default' })
export const db = drizzle(process.env.DATABASE_URL!, { schema, mode: 'default' })
Here's my example code:
export const auth0 = new Auth0Client({
beforeSessionSaved: async (session: SessionData) => {
const { sub, username, email, name, picture } = session.user
const attributes = {
id: sub,
avatar: picture,
username,
email,
name
}

await db.insert(users)
.values(attributes)
.onDuplicateKeyUpdate({
set: omit(attributes, ['id'])
})

return session
},
authorizationParameters: {
scope: "openid profile email",
},
})
export const auth0 = new Auth0Client({
beforeSessionSaved: async (session: SessionData) => {
const { sub, username, email, name, picture } = session.user
const attributes = {
id: sub,
avatar: picture,
username,
email,
name
}

await db.insert(users)
.values(attributes)
.onDuplicateKeyUpdate({
set: omit(attributes, ['id'])
})

return session
},
authorizationParameters: {
scope: "openid profile email",
},
})
Is there another method how I can connect to a MySQL database that doesn't rely on the URL global object? Thanks in advance
1 replies
DTDrizzle Team
Created by dmb on 7/11/2024 in #help
Unable to rename table
I'm attempting to rename ironclad_account_kills to ironclad_account_npc but I'm unable to. What might be causing this?
error: relation "ironclad_account_npc" does not exist
at /Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:43530:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:62596:21)
at async pgSuggestions (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:64890:19)
at async Command.<anonymous> (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:66233:11) {
length: 119,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '31',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '1449',
routine: 'parserOpenTable'
}
error: relation "ironclad_account_npc" does not exist
at /Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:43530:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:62596:21)
at async pgSuggestions (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:64890:19)
at async Command.<anonymous> (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:66233:11) {
length: 119,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '31',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '1449',
routine: 'parserOpenTable'
}
4 replies
DTDrizzle Team
Created by dmb on 4/26/2024 in #help
Converting a field from X type to Serial causes errors
I'm attempting to convert a field from type text to type serial. Here's the error I'm seeing:
error: type "serial" does not exist
at /Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:24462:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:25423:21)
at async Command.<anonymous> (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:63261:9) {
length: 89,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
error: type "serial" does not exist
at /Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:24462:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:25423:21)
at async Command.<anonymous> (/Users/dexter/projects/next/progress.quest/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:63261:9) {
length: 89,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
Here's the SQL generated:
ALTER TABLE "api_key" ALTER COLUMN "user_id" SET DATA TYPE serial;--> statement-breakpoint
ALTER TABLE "api_key" ALTER COLUMN "user_id" SET DATA TYPE serial;--> statement-breakpoint
I believe serial to simply be an integer datatype under the hood. So should this in fact be:
ALTER TABLE "api_key" ALTER COLUMN "user_id" SET DATA TYPE integer;--> statement-breakpoint
ALTER TABLE "api_key" ALTER COLUMN "user_id" SET DATA TYPE integer;--> statement-breakpoint
Any thoughts?
1 replies