Coder Social home page Coder Social logo

Comments (8)

jshear avatar jshear commented on August 16, 2024 1

I'm not planning to implement this now or in current version, especially if we go with #1639. You're probably better off implementing your own session management

What is the connection between user-defined adapters and this issue? Sorry if it's obvious, I'm just getting familiar with this library and trying to make sure I have a good understanding.

Even in the current V4, Lucia's validateSession is still handling expiration updates.

If the plan is to keep this logic within Lucia, I agree that a config could be useful to give control to the dev. For example, a extensionGracePeriod config where the expiration is extended if session.expiresAt.getTime() - Date.now() < extensionGracePeriod

from lucia.

pilcrowOnPaper avatar pilcrowOnPaper commented on August 16, 2024 1

To be honest, I just don't like callbacks.

import { SessionState } from "lucia";

const lucia = new Lucia(adapter, {
  checkSession: (session) => {
    if (Date.now() >= session.expiresAt.getTime()) {
      return SessionState.Invalid;
    }
    return SessionState.UpdateExpiration;
  },
}) 

You probably can update the expiration when retrieving the session too.

UPDATE session SET expires_at = expires_at + 2592000 RETURNING *;

from lucia.

wobedi avatar wobedi commented on August 16, 2024 1

@pilcrowOnPaper
To be honest, I just don't like callbacks.

I guess I wasn't thinking of the API as a callback.

I like the direction that @jshear hinted at above - something declarative like:

const lucia = new Lucia(adapter, {
    sessionExpiresIn: new TimeSpan(30, 'd'),
    refreshSessionAfter: new TimeSpan(1, 'd'),
}

You could continue to default refreshSessionAfter to half the time span of the expiry.
And devs could choose to refresh it earlier or later.

(happy to try my hand at a PR for this - if you agree with the direction)

from lucia.

doroved avatar doroved commented on August 16, 2024

E.g. for our use case I would love to customize this behavior to "refresh the session on every visit" instead of "only refresh the session if user happens visit in second half of their expiry period"

To put it simply, you want a session with no expiration date.

from lucia.

pilcrowOnPaper avatar pilcrowOnPaper commented on August 16, 2024

I'm not planning to implement this now or in current version, especially if we go with #1639. You're probably better off implementing your own session management

from lucia.

wobedi avatar wobedi commented on August 16, 2024

E.g. for our use case I would love to customize this behavior to "refresh the session on every visit" instead of "only refresh the session if user happens visit in second half of their expiry period"

To put it simply, you want a session with no expiration date.

Not quite - I want a session that expires if the user does not visit at any point in time before the expiry datetime

I'm not planning to implement this now or in current version, especially if we go with #1639. You're probably better off implementing your own session management

Fair. We might try to just build our own little "session refresh" logic for this and use Lucia otherwise. Will update here with result if we do that.

from lucia.

pilcrowOnPaper avatar pilcrowOnPaper commented on August 16, 2024

@jshear

What is the connection between user-defined adapters and this issue?

I'm not talking about adapters here; rather I think you'd be better off ditching Lucia completely and implementing sessions from scratch

from lucia.

wobedi avatar wobedi commented on August 16, 2024

@jshear

What is the connection between user-defined adapters and this issue?
@pilcrowOnPaper
I'm not talking about adapters here; rather I think you'd be better off ditching Lucia completely and implementing sessions from scratch

Seems drastic - would prefer to just configure refresh behavior. Loving Lucia otherwise.
Happy to try my hand at raising a PR for this, but only if you generally agree with the direction of course.

from lucia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.