Trying to set or reset the value of a secret with some User Input Text, so I can retrieve later when building headers. The Wix/Velo environment provides for CORS support from backend.

Updating the value seems easiest - after setting an initial value in the Secrets manager. But at this point, I’m looking to createSecret just to understand how the Javascript works.

Running into trouble figuring out how to create a placeholder variable inside a function called from aModule.jsw. Tried using a global variable myGlobal and attach the text as an object property twiHan.

aModule.jsw file:

import wixSecretsBackend from ‘wix-secrets-backend’;

export var myGlobal = {};

export function createNewSecret() {
const secret = {
name: “UserNamer”,
value: myGlobal.twiHan, //the function doesn’t like this term!
description: “Twitter Handle Temp Stor” //works with string value tho
};

return wixSecretsBackend.createSecret(secret)
.then((id) => {
return id;
})
.catch((error) => {
console.error(error);
});
}

And here’s the event handler code:

import { createNewSecret } from ‘aModule.jsw’;
import { myGlobal } from ‘aModule.jsw’;

function button3_click(event) {
myGlobal.twiHan = $w(“#input2”).value;
console.log(myGlobal.twiHan);
createNewSecret();
}

I’m a little unclear on the whole onReady() thing with Wix - waiting until page is loaded to declare button functionality. The code worked without it, but not with it. Strange. Also not completely clear on export function() versus function() when passing functions and objects between backend and front.

So, what basic protocols on variables and declaring properties am I missing here?

I’m not familiar with the way wix does these types of calls but the Twitter API does not support CORS.

Wix Velo supports backend calls to the Twitter API. And supposedly one can call these functions from a backend web module .jsw file, and pass variable through a “Secrets Manager” that keeps sensitive data out of the publicly available code.

My question is more about user input variables passing to imported backend functions. In a general , Javascript kind of way.

1 Like

ah ok, you might get an answer faster on Newest 'velo' Questions - Stack Overflow

1 Like

Pretty much solved it using function parameters, calling function from jsw module.

Thanks for the resource!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.