[1.4.0] MagicLink not working after upgrade
After upgrading to version 1.4, we I request a magic link I receive this error
ERROR [Better Auth]: null value in column "id" of relation "verification" violates not-null constraint
# SERVER_ERROR: error: null value in column "id" of relation "verification" violates not-null constraint
This is my config:
export const auth = betterAuth({
database: new Pool({
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT) || 5432,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
options: -c search_path=better_auth, // Use a separate schema for Better Auth
}),
advanced: {
cookiePrefix: 'app',
database: {
generateId: 'uuid',
},
},
user: {
additionalFields: {
firebaseUid: { type: 'string', required: false },
internalUserId: { type: 'string', required: false },
},
},
plugins: [
admin({
adminRoles: ['admin', 'superadmin'],
adminUserIds: adminUserIds,
}),
bearer(),
expo(),
magicLink({
sendMagicLink: async ({ email, token, url: originalUrl }) => {
const url = new URL(originalUrl);
const params = Object.fromEntries(url.searchParams.entries());
await sendMagicLinkEmail({
email,
token,
urlParams: params,
});
},
expiresIn: 60 * 60, // 1 hour
}),
],
});
If I downgrade to version 1.4.0-beta.20 it just works13 Replies
can you remove
uuid and try it
im guessing that's the issueyep, I removed uuid and it worked
Since I plan to use only uuid do you think I should wait for a fix for it?
cc @Max
seems like an issue with uuid
Just tested on drizzle and everything works, likely an issue in kysely adapter.
If I find anything I'll update.
Using ksyely with pg usually means the database handles generating the UUID.
Can you confirm that your current pg schema has uuid functions to generate it in your DB?
Yes, I had always uuid-ossp enabled, I tested enable pgcrypto and still didn't work
I don't know if it helps, but in beta 20, I was using UUID using the same configs, and better auth could generate uuid with no problem
does beta 21 fail? @varetalindinha
yep
Most likely caused by the new join feature.
Can you tell me what endpoint you were hitting before seeing the error?
Was it when sending off the magic link? or was it when clicking the URL provided by the magic link
Furthermore, is better-auth able to create any tables at all? or is it just this specific case which is failing?
the endpoint is POST /sign-in/magic-link, we I request the server to send the magic link
I just test POST sign-in/email and I had the same error (but I didn't test several others methods because I'm using only magic links now)
Better auth can create any tables that it needs in database but since I'm not using an ORM, I'm need to use the CLI
I ran npx @better-auth/cli generate but it says there is no migration needed
and here the error trace that better auth logs on server
I think the issue is with the migration CLI.
I get the same message stating schema is already up to date, yet the
id fields are still text.
After resetting my local pg db and running migrations again, I can see it correctly sets it to uuid.
@varetalindinha
I'll see what I can do to make it detect the migrations
if you just have a test project and are not worried about resetting a database, this will be the fastest solution to getting this working.Oh I see, I'll wait for a CLI update, I will stay in beta 20 for now. Thanks for the help