Anyone know why i'm getting this when building on vercel?
Unanswered
joshie posted this in #help-forum
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
joshieOP
can anyone help?
joshieOP
@Alfonsus Ardani ?
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?
joshieOP
its the default adapter file from @auth
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;
},
},
};
Oriental chestnut gall wasp
can I see your package.json
I think the issue may be with NextAuthOptions
I think it may be outdated
joshieOP
ok
Oriental chestnut gall wasp
I think what you're looking for is
https://authjs.dev/reference/nextjs#nextauthconfig
https://authjs.dev/reference/nextjs#nextauthconfig
joshieOP
hold on
Oriental chestnut gall wasp
NextAuthOptions is from pre v5 I believe
joshieOP
my code doesnt throw an invalid import though
Oriental chestnut gall wasp
That's because you're not importing anything invalid
It's just old
So the type definition is likely different
thats my package.json
Oriental chestnut gall wasp
you have
"next-auth": "^4.24.5",
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
joshieOP
ah
so i should find an old version of pg-adapter or upgrade to v5?
Oriental chestnut gall wasp
I believe the new package is called
@auth/core
Probably just upgrade to v5
joshieOP
aight
Oriental chestnut gall wasp
this is a personal project I'm assuming
and not a production app
joshieOP
its personal for now
i do plan to make it production eventually
the site is essentially just a skin for my api
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
joshieOP
v5 looks much different but i should be fine ig
Oriental chestnut gall wasp
yes
Oriental chestnut gall wasp
If it ends up working, just mark one of my answers as the solution
@joshie ts
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;
},
},
};
joshieOP
mind you this code works fine n all on just doing
npm run dev
Oriental chestnut gall wasp
I need to run some errands but good luck!
@Oriental chestnut gall wasp I need to run some errands but good luck!
joshieOP
i found some errors that arise with migrating to v5
so is there anyway to just roll back the postgres adapter?
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
joshieOP
i cant find any for v4
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
@Oriental chestnut gall wasp You should be able to look it up in the v4 docs
joshieOP
v4 docs redirect you to v5 adapters
this just leads to the "expiremental" branch
aka v5
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