Closed deadcoder0904 closed 9 months ago
In the code provided this looks to be a mismatch between the column name in the DB and what you're trying to access in getUserAttributes
. The column name and raw data from the DB (attributes) has it called emailVerified
. But in getUserAttributes
you're trying to access attributes.email_verified
. Hence why it is always undefined (that doesn't exist on attributes).
Try to access attributes.emailVerified
instead and it should work.
Put this in discord too but thought it best to comment here as well.
You'd have to be more specific for me to debug the issue. I need something reproducible. A minimal reproduction will help a lot here. Have you also checked if it's not an issue with Drizzle?
@pilcrowOnPaper the sqlite branch is the minimal reproduction itself. it is as small as possible. ik it has other functionalities like signup, login but its optional as you can do db:seed
to insert user data & then try login & verify email to see it doesn't work.
yes, i've checked straight for 2 days. i only use 2 packages: lucia
& @lucia-auth/adapter-drizzle
that exposes better-sqlite3
adapter.
i've also checked lucia packages & the code looks alright but it doesn't work on 2 separate repos of mine. i'd appreciate an example on email otp or email verification links in any framework. v2 worked but v3 isn't. i tried finding the bug but got nothing yet.
i'm 99% sure its a bug in lucia. i get undefined
. at least, 0
could've been understandable. the above false
only came because i wrapped it in Boolean
and Boolean(undefined)
is still false
. please take a look.
@LinusOP sorry i didn't see your comment above but its type-safe.
here's my schema:
export const userTable = sqliteTable("user", {
id: text("id", { length: 255 }).primaryKey(),
email: text("email", { length: 255 }).notNull().unique(),
emailVerified: integer("email_verified").notNull(),
but i'll give it a shot. this might be a dumb mistake on my part.
@LinusOP looks like you were right. i copy-pasted it straight as is from the lucia docs. and since it was type-safe, i didn't double-check.
i'm getting client-component error now but that worked i think:
{
result: {
user: {
emailVerified: 1,
email: 'a@a.com',
id: '01HNFKFVFC2AP11Z6YGXDWJ08B'
},
session: {
id: 'mw2093gumie0fim4fo3gja3lyf15riagcyjw3bgd',
userId: '01HNFKFVFC2AP11Z6YGXDWJ08B',
fresh: false,
expiresAt: 2024-01-31T11:36:10.000Z
}
}
}
{
user: {
emailVerified: 1,
email: 'a@a.com',
id: '01HNFKFVFC2AP11Z6YGXDWJ08B'
}
}
@pilcrowOnPaper i did find a couple of places for docs improvement. will probably send a pr now.
[...] and since it was type-safe, i didn't double-check.
Attributes is only typesafe based on your declared DatabaseUserAttributes
interface, it does not actually ensure that interface matches with your DB schema. And in this case it didn't, DB schema iwas emailVerified
but interface (and thus getUserAttributes
) used email_verified
.
So it's important to ensure that the interface matches the returned columns from the DB and your DB schema to get actual type safety.
yeah, i fucked up. i think docs also used email_verified
so i copy-pasted. see https://lucia-auth.com/guides/email-and-password/email-verification-codes
yeah, i fucked up. i think docs also used
email_verified
so i copy-pasted. see https://lucia-auth.com/guides/email-and-password/email-verification-codes
Easy mistake to make at the end of the day, most important is that it's resolved 😄
Package
lucia
Describe the bug
clone this repo & switch to
sqlite
branch to see the error -> https://github.com/deadcoder0904/next-13-lucia-auth-drizzle-turso-sqlite-magic-link/tree/sqlitei have tried lucia v3 in 2 different projects. the above one using email otp code & another is a private project using email verification links.
i always get
undefined
onemailVerified
if iconsole.log
something. this is from my private project:As you can see, the first time it shows
emailVerified: 1
which is logged inattributes
property insidenew Lucia
constructor:I'm logging
result
invalidateRequest
function like so:And my
dashboard/page.tsx
has the finaluser
logged:Both projects are quite similar so you can test out. I think its a bug in lucia itself. I'm unable to make email OTP or email links work in v3.
in v2, email links worked fine with copy-paste from docs. i didn't try email otp in v2 though so can't say about that.