adonisjs/session

session put data issue

Sunedge opened this issue · 4 comments

Prerequisites

We do our best to reply to all the issues on time. If you will follow the given guidelines, the turn around time will be faster.

  • Lots of raised issues are directly not bugs but instead are design decisions taken by us.
  • Make use of our forum, or discord server, if you are not sure that you are reporting a bug.
  • Ensure the issue isn't already reported.
  • Ensure you are reporting the bug in the correct repo.

Delete the above section and the instructions in the sections below before submitting

Package version

4.0.0

Node.js and npm version

5.6.0

Sample Code (to reproduce the issue)

Hello,
putting data in session impossible. I checked it's not big data.
Not giving any error.
Could you help me, please?
session.put('user-data', authResponse.body);
session.put('user-data2', "12345");//for this one not working

BONUS (a sample repo to reproduce the issue)

Hello,
putting data in session impossible. I checked it's not big data.
Not giving any error.
Could you help me, please?
session.put('user-data', authResponse.body);
session.put('user-data2', "12345");//for this one not working

Hello @thetutlage,
Could you help me, please?

Hey @Sunedge! 👋

Could you please be more descriptive of what you are trying to do, what happen and what you expect to happen.

Also, a repository to reproduce your issue would be great.

Hi @RomainLanz,
I want to put variables into session.
session.put('user-data', authResponse.body);
My data's size is 400 bytes. If user-data size increased it not working and not login.
The Problem is size of session (user-data).
If it's possible increase size session, how can I do it?
Please look at session.put('user-data', authResponse.body); line
Best regards.
//It's my code bellow
'use strict'

const Env = use('Env');

class AuthController {

async login({view,request,response,session,antl}) {
if (request.method() == "POST") {
try {
session.clear();
const username = request.input('username');
const password = request.input('password');

      const loginClient = use('sync-rest-client');
      const authResponse = await
      loginClient.post(Env.get('SAAS_SERVER_URL') + '/auth/login', {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        payload: "username=" + username + "&password=" + password
      });
      if(authResponse.statusCode==200){
        session.put('user-data', authResponse.body);

        const restClient = use('sync-rest-client');
        const menuDataResp = await
          restClient.post(Env.get('SAAS_SERVER_URL') + '/users/profile/menuDataByUserPermission', {
            headers: {
              'Content-Type': 'application/json',
              'Accept': 'application/json',
              'Authorization': 'Bearer ' + (session.get('user-data') ? session.get('user-data').access_token : '')
            }
          });

        session.put("menu-data",menuDataResp.body);

        response.redirect('/user/auto');
      } else if(authResponse.statusCode==401) {
        return view.render("user.login",{errors:antl.formatMessage('errors.auth_error')})
      } else if(authResponse.statusCode==500) {
        return view.render("user.login",{errors:antl.formatMessage('errors.auth_error_server')})
      }
    } catch (e) {
      return view.render("user.login",{errors:antl.formatMessage('errors.auth_error_server')})
    }
  } else {
    return view.render('user.login', {errors: null})
  }

}

async logout({response,session}) {
session.forget('user-data');
return response.redirect('/login');
}
}

module.exports = AuthController