Reputation: 79
I'm using Crypto2(https://www.npmjs.com/package/crypto2) library for Public/Private key production . I'm producing these keys while registering some patient as in code below.
Template.patient_register.events({
'submit form': function(event, template) {
event.preventDefault();
const {privateKey,publicKey} = await crypto2.createKeyPair();
var _email = event.target.registerEmail.value;
var _password = event.target.registerPassword.value;
var _disease_group = event.target.registerDisease_Group.value;
var _account_type = event.target.registerAccount_Type.value;
var _publickey = await crypto2.readPublicKey('key.pub');
console.log("Public Key Is:::"+_publickey);
console.log("Private Key Is:::"+await crypto2.readPrivateKey('key.pem'));
var newAccount = {
email : _email,
password : _password,
disease_group : _disease_group,
account_type : _account_type,
public_Key : _publickey
};
Accounts.createUser(newAccount, function(err) {
if (err) {
....................
} else {
.....................
}
});
template.find("form").reset();
}
});
But when I run this code it fails with an error "await is a reserved word". Please help me with this.
Upvotes: 0
Views: 180
Reputation: 101
(Async/await) is always used in pair. Whenever you create a function which contains statement await it must be used in pair with async.
function add(x,y){
return x+y;
}
// if you do not write async you will be prompt with (SyntaxError: await is only valid in async function)
async function test(){
const x = 1;
const y = 2;
const result = await add(x,y);
console.log(result) // 3
}
Upvotes: 1
Reputation: 696
You have to add the async
declatation to tell compiler that this function uses async functions and will have to await
them :
'submit form': async function(event, template) {
Upvotes: 1