Gregivy / simpleddp-plugin-login

Meteor.Accounts login plugin for simpleDDP
MIT License
12 stars 5 forks source link

error when bundling the js file #5

Closed smartgamer closed 4 years ago

smartgamer commented 4 years ago

Hi, When I tried to bundle the js file using browserify, : let userAuth = await server.login({ password, user: { username, }, });

I got an error message: SyntaxError: Unexpected token. This error happens at "await". If I remove "await", it seems work fine. Do you know what's the issue and how to solve this?

Thanks,

Gregivy commented 4 years ago

Hello @smartgamer. First of all your environment have to support async/await if not you should use babel + browserify to transpile async/await into a promise (also dont forget to useawaitkeyword only insideasyncfunctions). Either you can use promise.then()` method but your environment have to support promises anyway, if promises are not supported you can use babel or include pollyfills for promises yourself.

Example with .then():

let userAuth;
server.login({
  password,
  user: {
    username,
  },
}).then(function(token) {userAuth = token});
smartgamer commented 4 years ago

@Gregivy Thank you for your reply. It's solved now. I didn't know await has to be inside async.