Enable User Session In Strapi

4.9k Views Asked by At

I want to enable session for every user who requests for the token using the URL "/auth/local" which is the default API provided by Strapi. I guess Strapi is by default configured with Koa session but inspite of that no session cookie is returned in response by default.

What is the best way to enable session management in Strapi? Can anyone share their experience on this one ?

1

There are 1 best solutions below

1
On

Why do not you try using the mechanism of sessionStrage. I referred to this page of the official reference. (I used non-react part because I do not use it)

Plugin Development - Front-end Helpers - Auth https://strapi.io/documentation/plugin-development/utils.html#auth

github https://github.com/strapi/strapi-examples/tree/master/login-react/react-login-front-end-app

blog? https://medium.com/strapi/protected-routes-and-authentication-with-react-and-node-js-d31d234644cd

The source of auth.js is pretty helpful https://github.com/strapi/strapi-examples/blob/master/login-react/react-login-front-end-app/app/utils/auth.js

I POST from the request module and returned to json

auth.setToken (body.jwt, body.rememberMe)
auth.setUserInfo (body.user, body.rememberMe)

Then we kept the data in sessionStrage.

I do not know if it will be helpful, but maybe it may be useful, so I wrote it.

I am a Japanese who is not good at English, so I'm going to google translate as it is. Even if there is a strange part, I do not know, so please forgive that point.