Next.js Discord

Discord Forum

Anyone know why i'm getting this when building on vercel?

Unanswered
joshie posted this in #help-forum
Open in Discord
Avatar
joshieOP
Type error: Type 'import("/vercel/path0/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("/vercel/path0/node_modules/next-auth/adapters").Adapter'.
  Types of property 'createUser' are incompatible.
    Type '((user: AdapterUser) => Awaitable<AdapterUser>) | undefined' is not assignable to type '((user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>) | undefined'.
      Type '(user: AdapterUser) => Awaitable<AdapterUser>' is not assignable to type '(user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>'.
        Types of parameters 'user' and 'user' are incompatible.
          Property 'id' is missing in type 'Omit<AdapterUser, "id">' but required in type 'AdapterUser'.
  16 |
  17 | export const authOptions: NextAuthOptions = {
> 18 |   adapter: PostgresAdapter(pool),
     |   ^
  19 |   providers: [
  20 |     /*GitHubProvider({
  21 |       clientId: env.NEXT_PUBLIC_GITHUB_ID || '',
Error: Command "npm run build" exited with 1

66 Replies

Avatar
joshieOP
can anyone help?
Avatar
joshieOP
@Alfonsus Ardani ?
Avatar
Oriental chestnut gall wasp
It would help if you included some code but from the error it seems like the two adapter types are different. Could you give some more context, maybe from your postgres adapter file?
Avatar
joshieOP
its the default adapter file from @auth
heres the relevant code:
import PostgresAdapter from '@auth/pg-adapter';
import type { NextAuthOptions } from 'next-auth';
import DiscordProvider from 'next-auth/providers/discord';
import { Pool } from 'pg';
import { env } from '@/env.mjs';
const pool = new Pool({
  connectionString: env.DATABASE_URL,
  ssl: {
    rejectUnauthorized: false,
  },
});
export const authOptions: NextAuthOptions = {
  adapter: PostgresAdapter(pool),
  providers: [
    DiscordProvider({
      clientId: env.NEXT_PUBLIC_DISCORD_ID || '',
      clientSecret: env.NEXT_PUBLIC_DISCORD_SECRET || '',
    }),
  ],
  events: {
    async createUser(message) {
      console.log('createUser:', message);
      const { id } = message.user;
      const response = await fetch(
        `${env.SWIFTINBOX_API_URL}/v2/register/${id}?token=${env.SWIFTINBOX_CONNECTOR_SECRET}`
      )
        .then((res) => res.json())
        .catch((err) =>
          console.error('Failed to create user in swiftinbox:', err)
        );

      if (!response.ok) {
        console.error('Failed to create user in swiftinbox:', response);
      }
    },
  },
  callbacks: {
    async jwt({ token, account, user }) {
      if (account) {
        token.accessToken = account.access_token;
        token.id = user.id;
      }
      return token;
    },
    async session({ session, user }) {
      session.user = {
        ...session.user,
        id: user.id,
      };

      return session;
    },
  },
};
Avatar
Oriental chestnut gall wasp
can I see your package.json
I think the issue may be with NextAuthOptions
I think it may be outdated
Avatar
joshieOP
ok
Avatar
Oriental chestnut gall wasp
I think what you're looking for is
https://authjs.dev/reference/nextjs#nextauthconfig
Avatar
joshieOP
hold on
Avatar
Oriental chestnut gall wasp
NextAuthOptions is from pre v5 I believe
Image
Avatar
joshieOP
my code doesnt throw an invalid import though
Avatar
Oriental chestnut gall wasp
That's because you're not importing anything invalid
It's just old
So the type definition is likely different
Avatar
joshieOP
thats my package.json
Avatar
Oriental chestnut gall wasp
you have
"next-auth": "^4.24.5",
Avatar
joshieOP
so i have to upgrade to v5?
im new to using nextauth
ive only really used supabase
Avatar
Oriental chestnut gall wasp
Well you're using stuff from v5 already
    "@auth/mongodb-adapter": "^2.3.3",
    "@auth/pg-adapter": "^0.4.1",
But you're also using the old NextAuthOptions type from v4
So they aren't compatible
Avatar
joshieOP
ah
so i should find an old version of pg-adapter or upgrade to v5?
Avatar
Oriental chestnut gall wasp
I believe the new package is called
@auth/core
Probably just upgrade to v5
Avatar
joshieOP
aight
Avatar
Oriental chestnut gall wasp
this is a personal project I'm assuming
and not a production app
Avatar
joshieOP
its personal for now
i do plan to make it production eventually
the site is essentially just a skin for my api
Avatar
Oriental chestnut gall wasp
Well by that point, v5 will probably be even more stable
And v4 will be even older
Just follow the guide I sent on upgrading and get rid of the old package
Avatar
joshieOP
v5 looks much different but i should be fine ig
Avatar
Oriental chestnut gall wasp
yes
Avatar
joshieOP
yep, everythings prt much changed:
Image
Avatar
Oriental chestnut gall wasp
If it ends up working, just mark one of my answers as the solution
Avatar
joshieOP
mind you this code works fine n all on just doing npm run dev
alrighty
Avatar
Oriental chestnut gall wasp
I need to run some errands but good luck!
Avatar
joshieOP
i found some errors that arise with migrating to v5
so is there anyway to just roll back the postgres adapter?
Avatar
Oriental chestnut gall wasp
I’m not sure. You’d have to look at the adapters from v4
They wouldn’t be part of @auth
Avatar
joshieOP
i cant find any for v4
like at all
Avatar
Oriental chestnut gall wasp
No since @auth is the new name they moved to for v5
It would be part of the next-auth package most likely
You should be able to look it up in the v4 docs
Avatar
joshieOP
v4 docs redirect you to v5 adapters
Image
this just leads to the "expiremental" branch
aka v5
Avatar
Oriental chestnut gall wasp
I’m not sure then. I don’t have a lot of next-auth experience. So idk if the features you’re looking for are available in v4 or not
Avatar
joshieOP
f