gatho-party / gatho-website

GNU Affero General Public License v3.0
9 stars 1 forks source link

Encountering `adapter_error_createVerificationToken` after local DB standup #8

Closed MaxwellBo closed 2 years ago

MaxwellBo commented 2 years ago
next-auth][error][adapter_error_createVerificationToken]
https://next-auth.js.org/errors#adapter_error_createverificationtoken
Invalid p.verificationToken.create() invocation in
/Users/mb/gatho-website/node_modules/@next-auth/prisma-adapter/dist/index.js:34:64
  31 createSession: (data) => p.session.create({ data }),
  32 updateSession: (data) => p.session.update({ data, where: { sessionToken: data.sessionToken } }),
  33 deleteSession: (sessionToken) => p.session.delete({ where: { sessionToken } }),
→ 34 createVerificationToken: (data) => p.verificationToken.create(
  The provided database string is invalid. Error parsing connection string: invalid port number in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters. {
  message: '\n' +
    'Invalid p.verificationToken.create() invocation in\n' +
    '/Users/mb/gatho-website/node_modules/@next-auth/prisma-adapter/dist/index.js:34:64\n' +
    '\n' +
    '  31 createSession: (data) => p.session.create({ data }),\n' +
    '  32 updateSession: (data) => p.session.update({ data, where: { sessionToken: data.sessionToken } }),\n' +
    '  33 deleteSession: (sessionToken) => p.session.delete({ where: { sessionToken } }),\n' +
    '→ 34 createVerificationToken: (data) => p.verificationToken.create(\n' +
    '  The provided database string is invalid. Error parsing connection string: invalid port number in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.',
  stack: 'Error: \n' +
    'Invalid p.verificationToken.create() invocation in\n' +
    '/Users/mb/gatho-website/node_modules/@next-auth/prisma-adapter/dist/index.js:34:64\n' +
    '\n' +
    '  31 createSession: (data) => p.session.create({ data }),\n' +
    '  32 updateSession: (data) => p.session.update({ data, where: { sessionToken: data.sessionToken } }),\n' +
    '  33 deleteSession: (sessionToken) => p.session.delete({ where: { sessionToken } }),\n' +
    '→ 34 createVerificationToken: (data) => p.verificationToken.create(\n' +
    '  The provided database string is invalid. Error parsing connection string: invalid port number in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.\n' +
    '    at cb (/Users/mb/gatho-website/node_modules/@prisma/client/runtime/index.js:38681:17)',
  name: 'Error'
}

I assume this is to do with the fact that schema.prisma defines

datasource db {
  provider = "postgresql"
  url      = ""
}

you could define

url = env("DATABASE_URL_AU")

as per https://www.prisma.io/docs/reference/database-reference/connection-urls

but that simply recovers the uninterpolated DB URL "postgres://{username}:{password}@{database_url:{port}/{database_name}".

Any ideas?

jakecoppinger commented 2 years ago

Ah, so I used to have it set to url = env("DATABASE_URL") but I was unable to dynamically set the URL depending on what region Gatho finds itself in. See pages/api/auth/[...nextauth].ts for how I dynamically set the connection string.

I'm unsure if I can remove the url entirely from the schema and set it in the PrismaClient constructor - that was a StackOverflow response suggesting leaving it empty.

MaxwellBo commented 2 years ago

Okay, I have discovered my problem. I think I assumed that the database URL would have its values interpolated by Prisma.

I had to manually set them s.t.

DATABASE_URL_AU="postgres://mb:@localhost:5432/matrix_events"

I'll keep this open as a TODO to childproof the setup documentation a bit more.

jakecoppinger commented 2 years ago

@MaxwellBo how does that PR look for improving docs on this issue?