nuxt-modules / strapi

Strapi Module for Nuxt
https://strapi.nuxtjs.org
MIT License
624 stars 80 forks source link

Server responds with 401 after some time of inactivity, works after reload #275

Closed lnvglr closed 10 months ago

lnvglr commented 2 years ago

After some time of inactivity, api calls return a 401, when reloading (once or twice) it works.

I call the api using useStrapi4() and find(). The Public role has permission to find and findOne of the collection type I am querying.

The request:

...
mounted() {
  this.$strapi.find("home").then(({data}) => {
    this.page = data;
  });
},
...

The response:

{
  "data": null,
  "error": {
    "status": 401,
    "name": "UnauthorizedError",
    "message": "Missing or invalid credentials",
    "details": {}
  }
}

I have a hunch that it may have something to do the the JWT token, but I don't know how to debug it.

Strapi 4.1.9 Nuxt 3.0.0-rc.5 DB Postgres Hosted on Railway.app

kwiat1990 commented 1 year ago

A bit old but it can be related to Strapi’s default database connection settings. I have previously same issue, which could be fixed through increasing number of connections:

module.exports = ({ env }) => ({
  connection: {
    client: "postgres",
    connection: {
      host: env("DB_HOST", "127.0.0.1"),
      port: env.int("DB_PORT", 5432),
      database: env("DB_NAME", "devDB"),
      user: env("DB_USER", "devUser"),
      password: env("DB_PASSWORD", "devPassword"),
      ssl: false,
    },
    pool: {
      min: 0,
      max: 10,
    },
    debug: false,
  },
});