lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
MIT License
9.25k stars 471 forks source link

[Docs]: Is there any way to update user session? #1442

Closed wiscaksono closed 7 months ago

wiscaksono commented 7 months ago

Description

is there any way to update user session without relogin the app in next js app router?

mfissehaye commented 7 months ago

+1

mfissehaye commented 7 months ago

I don't think there is a direct way to do it but here is how I am doing it. lucia.createSession accepts a third argument { sessionId?: string }. You can destroy the current session by lucia.invalidateSession(sessionId) and create another one with the new attributes and sessionId.

await lucia.invalidateSession(session.id);
const session = await lucia.createSession(session.userId, newAttributes, { sessionId });

You have to call invalidateSession first, otherwise the unique constraint on sessionId will complain.

pilcrowOnPaper commented 7 months ago

Lucia doesn't provide an API to update sessions - use your own driver/client/ORM

sleeyax commented 6 months ago

Is there a particular reason Lucia doesn't provide an API to update session data? I expected lucia.createSession(...) to update the session data if an already existing sessionId is being passed in. But instead it only performs an insert, resulting in duplicate entry errors.