Error message when using Session Manager

Every was ok, then i have this error :slight_smile:

VM41:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse ()
at sessionManager.js:28
at Array.reduce ()
at n.getData (sessionManager.js:26)
at n.render (sessionManager.js:22)
at n.constructor (BaseComponent.js:20)
at n (appConnect.js:490)
at n.e.hasOwnProperty.e.constructor (appConnect.js:523)
at new n (appConnect.js:490)
at n.$addChild (BaseComponent.js:213)

What server model are you using and where/when do you see this error?

i’m actually working on http://my-lovely-planet.com/

You did not really answer my questions :slight_smile: Please describe the problem more detailed.

Within a flow, when i use this :

{action: `mlpsession.set(\'role\',userdetail.data.query1[0].idrole)` }}

i have this error :

VM41:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at sessionManager.js:28
    at Array.reduce (<anonymous>)
    at n.getData (sessionManager.js:26)
    at n.render (sessionManager.js:22)
    at n.constructor (BaseComponent.js:20)
    at n (appConnect.js:490)
    at n.e.hasOwnProperty.e.constructor (appConnect.js:523)
    at new n (appConnect.js:490)
    at n.$addChild (BaseComponent.js:213)

Can you please paste your whole flow code and how do you call it?
Also make sure to follow the rules for pasting code in your post to make them more easily readable: How to format code in your posts

	<div class="container text-center">
					<div class="row justify-content-center">
						<form class="text-center border border-light p-5" method="post" is="dmx-serverconnect-form" id="serverconnectform1" action="dmxConnect/api/Login/login.php" dmx-on:unauthorized="notifies1.warning('Wrong Identification')"
							dmx-on:forbidden="mlpsession.set('connected',0)"
							dmx-on:success="run([{run:{action:`mlpsession.set(\'connected\',true)`}},{run:{action:`mlpsession.set(\'email\',email.value)`}},{run:{action:`userdetail.load()`}},{run:{action:`mlpsession.set(\'role\',userdetail.data.query1[0].idrole)`,disabled:true}},{run:{action:`mlpbrowser.goto(\'search.php\')`,disabled:true}}])">

							<div class="col-md-5 col-lg-12">
								<label class="sr-only" for="email">Email</label>
								<input class="form-control my-3 bg-light" id="email" type="email" placeholder="Email" required="" data-rule-email="" name="email"><label class="sr-only" for="input2-signin-02">Name</label>
								<label class="sr-only" for="password">Password</label>
								<input class="form-control my-3 bg-light" id="password" type="password" placeholder="Mot de passe" required="" name="password">
								<div class="d-flex">
									<button class="btn btn-outline-primary btn-block py-2 mr-3" type="submit">Connectez vous</button>
									<button class="btn btn-primary btn-block py-2 mt-0">Cr&eacute;ez un compte</button>
								</div>
								<p class="text-secondary text-muted mt-3">By signing in you agree with the <a href="#">Terms and Conditions</a> and <a href="#">Privacy Policy</a>.</p>
							</div>
						</form>
					</div>
				</div>

I can’t see any error with your code, also i see no error on the link your provided, when i log in.

ok then, can you execute the page www.my-lovely-planet.com/test.php.

Its only a session manager, a flow (auto run) and a sc to call user detail

I have the same error

<html>

<head>
	<base href="/">
	<script src="dmxAppConnect/dmxAppConnect.js"></script>
	<meta charset="UTF-8">
	<title>Untitled Document</title>
	<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="bootstrap/4/css/bootstrap.min.css" />
	<script src="dmxAppConnect/dmxStateManagement/dmxStateManagement.js" defer=""></script>
</head>

<body is="dmx-app" id="mylovelyplanet">
	<dmx-session-manager id="mlpsession"></dmx-session-manager>
	<script is="dmx-flow" id="flow1" type="text/dmx-flow" autorun="autorun">[
  {
    run: {action: "{{userdetail.load()}}"}
  },
  {
    run: {action: "{{mlpsession.set('email',userdetail.data.query1[0].email)}}"}
  }
]</script>
	<dmx-serverconnect id="userdetail" url="dmxConnect/api/Login/userdetail.php" noload="noload"></dmx-serverconnect>
	<script src="bootstrap/4/js/popper.min.js"></script>
	<script src="bootstrap/4/js/bootstrap.min.js"></script>
</body>

</html>

That’s a problem in your logic.
Your server connect does not run on page load, then you run a flow which runs the server action, and also runs a set session step.

All the steps executed using the “Run” steps are executed asynchronously, and they don’t wait for the previous one to complete. So in your case the server action runs, but also set session runs at the same time.
When the set session step runs the data from userdetail.data.query1[0].email is not yet available as the server action has not finished loading, so the value set for the session is undefined:

and that is why then you see the error in the console:

Maybe if you explain what are you trying to achieve we will be able to help you improve the logic.

Ok, i didn’t remember it was asynchrone … i will chnage the logic

You don’t really need to use a flow for that.
Just use the dynamic events of the button to run the server action on click and then onsuccess of the server action set the session.

Yes, but i was beliving that flow was synchron …

It’s working, but have another issue that i need to investigate…i come back to you after other test

All the steps except for the Run one are synchronous.

Maybe a new feature to add with a checkbox … “wait for completion”