Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable User Session In Strapi

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 ?

like image 335
Rishi Avatar asked May 30 '26 07:05

Rishi


1 Answers

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.

like image 111
eysmnje Avatar answered Jun 01 '26 20:06

eysmnje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!