[SOLVED] How to change session token expiration time?

As in https://docs.moralis.io/moralis-dapp/users/sessions#session-properties, I see

  • expiresAt (readonly): Approximate UTC date when this Session object will be automatically deleted. You can configure session expiration settings (either 1-year inactivity expiration or no expiration) in your appโ€™s Moralis Dashboard settings page.

But canโ€™t find the setting on the dashboard, or did I miss something? :sweat_smile:

Maybe it is referring to this column.

image

Thanks anyway, but I want to change the default expiration time.

Currently, I saw a default 1 year expiration time for each sessionToken.
Can it change to something like a week or a day?

you can not change de default expiration time in the interface. you can use a hook like beforeSave or afterSave to change that expiration time value, for example change it to a day if it is greater than a day

1 Like

Big thanks mate! need to add a little more workaround code :sweat_smile:

1 Like

Hello @mrgz,

Did you solve this problem? How did you solve it?

I tried these codes. But nothing happened.

const logger = Moralis.Cloud.getLogger();

Moralis.Cloud.afterSave("Session", async (request) => {
  try {
    logger.info(
      "afterSave Session -> request.object :: " + JSON.stringify(request.object)
    );
  } catch (error) {
    logger.info("afterSave Session -> error :: " + error);
  }
});

Moralis.Cloud.afterSave("_Session", async (request) => {
  try {
    logger.info(
      "afterSave _Session -> request.object :: " +
        JSON.stringify(request.object)
    );
  } catch (error) {
    logger.info("afterSave _Session -> error :: " + error);
  }
});

Moralis.Cloud.afterSave(Moralis.Session, async (request) => {
  try {
    logger.info(
      "afterSave Moralis.Session -> request.object :: " +
        JSON.stringify(request.object)
    );
  } catch (error) {
    logger.info("afterSave Moralis.Session -> error :: " + error);
  }
});