# Parsing Error: Unexpected Token {

**URL:** <https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [September 27, 2018, 10:22am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599 "2018-09-27T10:22:46Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![contactlenzo](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@contactlenzo](https://forum.wixstudio.com/u/contactlenzo)\
**Post date:** [September 27, 2018, 10:22am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/1 "2018-09-27T10:22:46Z")

</div>

Hi there,

I have added some code to my site and it seems like the code is right but I keep getting the “Parsing Error: Unexpected Token {” message. Please could someone assist? Here is my code:

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/9/e952a910d237d997a4f8231d269d1366a8c48e4e.png)

Kind regards

Lenzo

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [September 27, 2018, 10:48am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/2 "2018-09-27T10:48:36Z")

</div>

Hi Lenzo!

Please share a link to your site or the full code you use on that page so one of us, the WixCode team, can inspect it and provide you with a solution.

Doron.

---

<div class="post-metadata">

**Author:** ![contactlenzo](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@contactlenzo](https://forum.wixstudio.com/u/contactlenzo)\
**Post date:** [September 27, 2018, 10:51am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/3 "2018-09-27T10:51:34Z")

</div>

Hi there Doron,

That’s the only code I’m running thus far. Here is the link to the site: [https://officiallenzo.wixsite.com/rivoltare](https://officiallenzo.wixsite.com/rivoltare)

I look forward to your response.

---

<div class="post-metadata">

**Author:** ![contactlenzo](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@contactlenzo](https://forum.wixstudio.com/u/contactlenzo)\
**Post date:** [September 27, 2018, 10:53am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/4 "2018-09-27T10:53:16Z")

</div>

Just In case you want to see the full code in text:

**import** wixUsers **from** ‘wix-users’;  
$w.onReady( **function** () {  
//TODO: write your page related code here…

```
$w("#button9").hide(); 

```

});

**let** user = wixUsers.currentUser;

**let** userId = user.id; // “r5cme-6fem-485j-djre-4844c49”  
**let** isLoggedIn = user.loggedIn; // true

**if** (!isLoggedIn) { wixLocation.to(“/login”); }

**let** userRole;  
**let** userEmail;

user.getEmail()  
.then((email) =\> {  
userEmail = email;

```
        user.getRoles() 
            .then((roles) => { 
                    userRole = roles[0].name; 

```

// After the roles have been defined check them!  
**if** (user.role === “Free Membership” && (isLoggedIn = user.loggedIn)

```
                        { 
                            $w("#button9").show(); 
                        } **else** { $w("#button9").hide(); }

```

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [September 27, 2018, 11:22am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/5 "2018-09-27T11:22:41Z")

</div>

Hi Lenzo!

Your code was missing some parenthesis and brackets.  
Also, the command of importing the WixLocation API was missing.

Your code should look something like that:

```javascript
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

$w.onReady(function () {
    $w("#button9").hide();
});

let user = wixUsers.currentUser;

let userId = user.id;
let isLoggedIn = user.loggedIn;

if (!isLoggedIn) {
    wixLocation.to("/login");
}

let userRole;
let userEmail;

user.getEmail()
    .then((email) => {
        userEmail = email;
        user.getRoles()
            .then((roles) => {
                userRole = roles[0].name;

 if (user.role === "Free Membership" && (isLoggedIn = user.loggedIn)) {
                    $w("#button9").show();
                } else {
                    $w("#button9").hide();
                  }

            })
    })

```

Let me know if its working for you.  
I hope it helps!

Doron.

---

<div class="post-metadata">

**Author:** ![contactlenzo](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@contactlenzo](https://forum.wixstudio.com/u/contactlenzo)\
**Post date:** [September 27, 2018, 11:32am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/6 "2018-09-27T11:32:18Z")

</div>

This restores the login condition and that is now working again. Thank you! I have noticed however that my user.role is undefined. I was under the impression that the user role changes if the user has bought a paid plan. I have a plan on my site called “Free Membership” and I’ve signed in as the user that has the free membership but the #button9 isn’t being displayed. Is there something I’m missing?

---

<div class="post-metadata">

**Author:** ![contactlenzo](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@contactlenzo](https://forum.wixstudio.com/u/contactlenzo)\
**Post date:** [September 27, 2018, 11:52am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/7 "2018-09-27T11:52:10Z")

</div>

I double check and it seems as though paid plans don’t create a role when a user purchases them but reserve the role name anyway which means you can’t create a role that has the same name as your paid plan but you can’t refer to the already reserved role name of the paid plan either.

Is there perhaps a way to reference the users plan instead of their role?

---

<div class="post-metadata">

**Author:** ![sitedevelopements](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sitedevelopements](https://forum.wixstudio.com/u/sitedevelopements)\
**Post date:** [July 6, 2019, 9:42am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/8 "2019-07-06T09:42:05Z")

</div>

Has anyone seen this color pattern before the color appears to operational or is the code just completely wrong I am trying to change the property id content from 1 page name to a new page name it was a duplicate copy of one to another but I need to align the property ID to the second page name they do not conflict in the site

 ![](https://us1.discourse-cdn.com/wix/original/3X/9/d/9d963b5e587e98fc4f90884555331095a21e1ae5.png)

---

<div class="post-metadata">

**Author:** ![kevinsaptel](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kevinsaptel/32/11688_2.png) [@kevinsaptel](https://forum.wixstudio.com/u/kevinsaptel)\
**Post date:** [July 6, 2019, 10:52am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/9 "2019-07-06T10:52:39Z")

</div>

If it’s supposed to be an arrow function that returns an object, you should wrap it further with parentheses.

```javascript
data: () => ({
  date: null,
  // ...
});

```

Otherwise JS will try to interpret it as a function block.

---

<div class="post-metadata">

**Author:** ![sitedevelopements](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sitedevelopements](https://forum.wixstudio.com/u/sitedevelopements)\
**Post date:** [July 6, 2019, 11:07am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/10 "2019-07-06T11:07:48Z")

</div>

I managed to remove the unexpected token placing another set of parenthese but the code did still not change the ID content

 ![](https://us1.discourse-cdn.com/wix/original/3X/9/c/9c1960143026d387d6021be6d3eb43c840b9b263.png)

---

<div class="post-metadata">

**Author:** ![sitedevelopements](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sitedevelopements](https://forum.wixstudio.com/u/sitedevelopements)\
**Post date:** [July 6, 2019, 11:11am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/11 "2019-07-06T11:11:15Z")

</div>

This the error on preview

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/d/8d953aeaa5fbef5a45c38991a96a01ac4d2962d8.png)

---

<div class="post-metadata">

**Author:** ![kevinsaptel](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kevinsaptel/32/11688_2.png) [@kevinsaptel](https://forum.wixstudio.com/u/kevinsaptel)\
**Post date:** [July 6, 2019, 11:37am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/12 "2019-07-06T11:37:06Z")

</div>

Can you send me a code file?

---

<div class="post-metadata">

**Author:** ![malaysiaindiaevisa](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@malaysiaindiaevisa](https://forum.wixstudio.com/u/malaysiaindiaevisa)\
**Post date:** [October 16, 2019, 8:04am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/13 "2019-10-16T08:04:57Z")

</div>

Parsing Error: Unexpected Token

have added some code to my site and it seems like the code is right but I keep getting the “Parsing Error: Unexpected Token {” message. Please could someone assist? Here is my code:

here is my code

**import** {createToken, encodeCard} **from** “public/stripeAPI.js”;  
**import** {charge} **from** ‘backend/stripeProxy’;  
**var** payment;  
export function payNow(event) {  
createToken(encodeCard(createCard()))  
.then((token) =\> {  
console.log("Card token: " + token);  
charge(token, payment)  
.then((chargeResponse) =\> {  
console.log("Charge ID: " + chargeResponse.id);  
});  
});  
}

export function pay\_click(event) {  
payNow();

```
} 

```

export function amount\_change(event) {  
changeSate();  
}

**function** changeSate() {  
**let** payment = {  
“amount”: ($w(“#amount”).value \* 100),  
“currency”: “USD”,

```
} 

```

**function** createCard() {  
**return** {  
“name”: $w(“#cardholder”).value,  
“number”: $w(“#cardnum”).value,  
“cvc”: $w(“#cvc”).value,  
“exp\_year”: $w(“#year”).value,  
“exp\_month”: $w(“#month”).value

```
};

```

---

<div class="post-metadata">

**Author:** ![ryan90150](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ryan90150](https://forum.wixstudio.com/u/ryan90150)\
**Post date:** [November 12, 2019, 5:16pm UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/14 "2019-11-12T17:16:40Z")

</div>

Hello! I am also encountering an unexpected token error.

My goal is to try and collapse a video player when a URL does not exist in the database field. I also want to hide text (a header) when the text field is empty in the database. This is for multiple text sections.

When I use the collapse video function alone, it works fine. However, when I combine it with the hiding functions for the text, it does not work.

Does anyone have any suggestions?

Thank you for your help!

$w.onReady( **function** () {  
$w(“#dynamicDataset”).onReady(() =\> {  
**var** item = $w(“#dynamicDataset”).getCurrentItem(“#videoYouTube”);  
**if** (!item.video) {$w(“#videoPlayer1”).collapse();}  
});

$w.onReady( **function** () {  
$w(“#dynamicDataset”).onReady(() =\> {  
**var** item = $w(“#dynamicDataset”).getCurrentItem();  
**if** (item[“#CareerHighlights”] === **null** ) $w(“#text21”).hide();  
**else** $w(“#text21”).show() ;  
});  
});

$w.onReady( **function** () {  
$w(“#dynamicDataset”).onReady(() =\> {  
**var** item = $w(“#dynamicDataset”).getCurrentItem();  
**if** (item[“#Testimonials”] === **null** ) $w(“#text23”).hide();  
**else** $w(“#text23”).show() ;  
});  
});  
$w.onReady( **function** () {  
$w(“#dynamicDataset”).onReady(() =\> {  
**var** item = $w(“#dynamicDataset”).getCurrentItem();  
**if** (item[“#SetUp”] === **null** ) $w(“#text25”).hide();  
**else** $w(“#text25”).show() ;  
});  
});  
$w.onReady( **function** () {  
$w(“#dynamicDataset”).onReady(() =\> {  
**var** item = $w(“#dynamicDataset”).getCurrentItem();  
**if** (item[“#Introduction”] === **null** ) $w(“#text28”).hide();  
**else** $w(“#text28”).show() ;  
});  
});  
$w.onReady( **function** () {  
$w(“#dynamicDataset”).onReady(() =\> {  
**var** item = $w(“#dynamicDataset”).getCurrentItem();  
**if** (item[“#Pricing”] === **null** ) $w(“#text30”).hide();  
**else** $w(“#text30”).show() ;  
});  
});

---

<div class="post-metadata">

**Author:** ![barb](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/barb/32/11137_2.png) [@barb](https://forum.wixstudio.com/u/barb)\
**Post date:** [March 1, 2020, 1:25am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/15 "2020-03-01T01:25:20Z")

</div>

Hello, I have a similar problem. Parsing error with onReady function - I think I’m close!

SITUATION: I am trying to filter a data collection by the login user’s email address. As Admin I have added the initial records to the collection and need the ability for my members to update their address information as needed.

More than half of our members may not edit their information nor go online at all but I need everyone’s info for our roster (which is displayed in a repeater on a page visible to Members). Many of our members are elderly and are not computer savvy.

As admin, I add the initial record when I approve the member at registration

Here is the code I am using to fill an input field with the logged in user’s email address and then trying to use that to filter the data collection which is Read/Write so they can then edit it (on a Member page). I have a parsing error and can’t figure out what token is missing to make the code work. I hope someone can take a quick look to help.

* * *

**import** wixUsers **from** ‘wix-users’;  
**import** wixData **from** “wix-data”;

$w.onReady( **function** ()  
{ $w(“#dataset5”).onReady( () =\> { //DocentRoster data [set](http://user.id/)  
[**let**](http://user.id/) [user = wixUsers.currentUser;](http://user.id/)  
[**let**](http://user.id/) [userId = user.id;](http://user.id/)  
[**let**](http://user.id/) [isLoggedIn = user.loggedIn;](http://user.id/)  
[**let**](http://user.id/) [userRole = user.role; user.getEmail() .then( (email) =\> {](http://user.id/)  
[**let**](http://user.id/) [userEmail = email;](http://user.id/)  
[$w(‘#input40’).value = userEmail; $w(“#dataset5”).setFieldValue(“loginEmail”,$w(‘#input40’).value);](http://user.id/)  
[**let**](http://user.id/) [filter = $w(“#input40”).value; $w(“#dataset5”).setFilter(wixData.filter().contains(“docentEmail”, filter));](http://user.id/)

[wixData.query(“DocentRoster”)](http://user.id/)  
[.contains(“docentEmail”,$w(“#input40”).value)](http://user.id/)  
[.find()](http://user.id/)  
[.then(res =\> { $w(‘#box35’).expand();](http://user.id/)

[}](http://user.id/)  
[);](http://user.id/)

* * *

Box35 has the fields I want the user to be able to edit (address, phone, comments, preferences, etc.). All are from the DocentRoster set up as Read/Write with no filter.

Thanks in advance if anyone can spot what’s I’ve done wrong.

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [March 1, 2020, 2:04am UTC](https://forum.wixstudio.com/t/parsing-error-unexpected-token/4599/16 "2020-03-01T02:04:06Z")

</div>

This post is from 2018 and is being closed.  
Please add your own issue into a new post instead of bumping up an old post.  
Also, add any code in a code block as stated in the [Forum Guidelines.](https://www.wix.com/corvid/forum/community-discussion/corvid-community-guidelines)

You might want to look at something like a Member Profile as in this tutorial here.  
[https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area](https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area)
