Login () method code help

I added the following code from the login() method found in the wix-users-backend
API. I am not new to OOP, but I’m still learning Java. I can’t seem to find an explanation to the syntax of the return statements (and therefore what to do with the returned results). They appear to be objects, but the first return with sessionToken doesn’t seem to be a key:value pair and “approved” and “reason” are in double-quotes, which I thought was incorrect. Thanks in advanced.

export function myBackendFunction(email, password) {
4  return wixUsersBackend.login(email, password)
5    .then( (sessionToken) => {
6      return {sessionToken, "approved": true};
7    } )
8    .catch( (error) => {
9      return {"approved": false, "reason": error};
10    } );
11}

Line 6 is wrong.
You’re returning an object. Object should only contain couples of keys and values.
like {key1: value1, key2: value2}
But you put there: sessionToken which is value only.

Well, that is what I thought too. This is the sample code Velo has posted next to the login () function:
https://www.wix.com/velo/reference/wix-users-backend/login

Figured the code had been vetted, but maybe not. I am not qualified to criticize since I am so new to Java. Thank you for the response.

In JavaScript, we have a few syntaxes for declaration of an object properties

const value = "Property value";

// in ES5
const a = { value: value }; // ES5

const b1 = { "value": value }; // key as a string
const b2 = { 'value': value }; // the same

// in ES6
const c = { value }; //the same as { value: value };

// and Dynamic Property Keys
const key = 'value';
const d = { [key]: value };

all examples are valid and supported in JavaScript

Object Property Value Shorthand in JavaScript with ES6
https://alligator.io/js/object-property-shorthand-es6/

How to Set Dynamic Property Keys with ES6

@look4zebras Yes. The error is in the docs. It should be:

return {"sessionToken": sessionToken, "approved": true};

Sorry, I wrote before I read Alexander’s answer.
And I didn’t know that.
So maybe the issue is somewhere else. You’ll have to debug your code.

Alex,
Thank you for that answer and the links. That helped explain why there was a key:value pair with no key! Essentially…

return{sessionToken, "approved":true};

is the same as…

return{"sessionToken":sessionToken, "approved":true};

Now I can write the client-side code knowing how to use the values being returned. Cheers!

Hello i need help idont know what i have done wrong here
can anyone help please

import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;

$w . onReady ( function () {
$w ( ‘#login’ ). onClick ( function () {
let email = $w ( ‘#email’ ). value ;
let password = $w ( ‘#password’ ). value
wixUsers . login ( email , password )
. then (()=>{
wixLocation . to ( ‘/the-dashboard’ );