How to fix a Prisma LinkAccountError 'The provided value for the column is too long for the column's type.'
Asked Answered
H

1

6

I got an error using Next Auth with Prisma Adapter on create-t3-app. I successfully added data on my Planetscale database.

I got this error when I try to log in using Next Auth Google Provider. There is also Discord Provider which I can log in and create an account as well as a User linked to the account. I cannot create an account using Google due to the error below.

prisma:query BEGIN
prisma:query INSERT INTO `foo`.`Account` (`id`,`userId`,`type`,`provider`,`providerAccountId`,`access_token`,`expires_at`,`token_type`,`scope`,`id_token`) VALUES (?,?,?,?,?,?,?,?,?,?)
prisma:query ROLLBACK
prisma:error
Invalid `p.account.create()` invocation in
~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42

  16 },
  17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),
  18 deleteUser: (id) => p.user.delete({ where: { id } }),
→ 19 linkAccount: (data) => p.account.create(
The provided value for the column is too long for the column's type. Column: for
[next-auth][error][adapter_error_linkAccount]
https://next-auth.js.org/errors#adapter_error_linkaccount
Invalid `p.account.create()` invocation in
~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42

  16 },
  17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),
  18 deleteUser: (id) => p.user.delete({ where: { id } }),
→ 19 linkAccount: (data) => p.account.create(
The provided value for the column is too long for the column's type. Column: for {
  message: '\n' +
    'Invalid `p.account.create()` invocation in\n' +
    '~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n' +
    '\n' +
    '  16 },\n' +
    '  17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),\n' +
    '  18 deleteUser: (id) => p.user.delete({ where: { id } }),\n' +
    '→ 19 linkAccount: (data) => p.account.create(\n' +
    "The provided value for the column is too long for the column's type. Column: for",
  stack: 'Error: \n' +
    'Invalid `p.account.create()` invocation in\n' +
    '~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n' +
    '\n' +
    '  16 },\n' +
    '  17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),\n' +
    '  18 deleteUser: (id) => p.user.delete({ where: { id } }),\n' +
    '→ 19 linkAccount: (data) => p.account.create(\n' +
    "The provided value for the column is too long for the column's type. Column: for\n" +
    '    at fn.handleRequestError (~/node_modules/@prisma/client/runtime/library.js:174:6477)\n' +
    '    at fn.handleAndLogRequestError (~/node_modules/@prisma/client/runtime/library.js:174:5907)\n' +
    '    at fn.request (~/node_modules/@prisma/client/runtime/library.js:174:5786)\n' +
    '    at async t._request (~/node_modules/@prisma/client/runtime/library.js:177:10477)',
  name: 'Error'
}
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR]
https://next-auth.js.org/errors#oauth_callback_handler_error
Invalid `p.account.create()` invocation in
~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42

  16 },
  17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),
  18 deleteUser: (id) => p.user.delete({ where: { id } }),
→ 19 linkAccount: (data) => p.account.create(
The provided value for the column is too long for the column's type. Column: for Error:
Invalid `p.account.create()` invocation in
~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42

  16 },
  17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),
  18 deleteUser: (id) => p.user.delete({ where: { id } }),
→ 19 linkAccount: (data) => p.account.create(
The provided value for the column is too long for the column's type. Column: for
    at fn.handleRequestError (~/node_modules/@prisma/client/runtime/library.js:174:6477)
    at fn.handleAndLogRequestError (~/node_modules/@prisma/client/runtime/library.js:174:5907)
    at fn.request (~/node_modules/@prisma/client/runtime/library.js:174:5786)
    at async t._request (~/node_modules/@prisma/client/runtime/library.js:177:10477) {
  name: 'LinkAccountError',
  code: 'P2000'
}
Hellraiser answered 11/4, 2023 at 21:51 Comment(1)
Related Issue: github.com/nextauthjs/next-auth/issues/4734Nacred
H
9

What I had to do is to add a native database type @db.Text on my schema.prisma file. Could someone explain why Discord did not require this setting whereas Google did?

model Account {
  id                String  @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String? @db.Text
  access_token      String? @db.Text
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String? @db.Text
  session_state     String?
  user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
  @@index([userId])
}
Hellraiser answered 11/4, 2023 at 22:1 Comment(1)
Thank you so much! They need better error messages. I had the same issue and @db.MediumText fixed it. The logs were telling me the wrong column name, a column name that didn't exist, so I've been so confused for like 2 days.Benignity

© 2022 - 2024 — McMap. All rights reserved.