-
-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: custom sessionId does not work with Drizzle adapter #1660
Comments
It's because you're passing |
Oh my god I'm so stupid! |
I am thinking about this: Maybe we could modify the code of the Drizzle adapter to avoid the possibility of this overriding. I think that when we set a custom session ID, this custom ID should be used even if an The following code can be a solution. public async setSession(session: DatabaseSession): Promise<void> {
await this.db.insert(this.sessionTable).values({
...session.attributes,
id: session.id,
userId: session.userId,
expiresAt: session.expiresAt
});
} If you want to keep the possibility to set an const sessionId = options?.sessionId ?? attributes.id ?? generateIdFromEntropySize(25); This way, if a custom ID exists, it has priority over the Another option could be removing the What do you think about this idea ? |
Yeah I didn't close the issue :D |
Do you want me to contribute by proposing the solution I described above in a pull request ? |
Package
@lucia-auth/session-drizzle
Describe the bug
Hi!
When I create a new session with
lucia.createSession
for a user who already has an existing session, a duplication key error is thrown by the database:For information, the
userId
used here is the integer1
.It seems that the
userId
is always used by default to set thesessionId
. ThesessionId
is not auto incremented.To fix this, I wanted to set a custom
sessionId
this way:But it does not work.
It seems that
lucia.createSession
does not care about my customsessionId
. It still insert a1
as thesessionId
.If I try to do it with an other user, the same thing happen. For example, I try with a user with an id
2
. So thesessionId
was using theuserId
and the session was inserted with the id2
. If I try to create another session for the same user, the same error will be thrown.So finaly I tried to do it manually, by skipping the usage of
lucia.createSession
and directly using the DB client:And it works ! So this way I am sure that the problem does not come from my table schema or any database configuration.
Maybe I could help finding the origin of the problem and fix it ?
Thank you in advance for your help !
The text was updated successfully, but these errors were encountered: