top of page

Published: January 22, 2020

Updated: January 22, 2020

0

45

NEW Wix Feature - Wix Secrets Manager - Protect your APIs and Secrets

Category(s)

-Side Menu-
Category

Title

Here is the helpful code to get you going! Let me know if you need any more assistance in the comments on YouTube or contact me at the bottom today!


You can also find a more in-depth example here: https://bit.ly/2MVPtVE


FYI: Just to give you a little background on the secrets manager, this process lets you securely store secrets such as API keys. The value of each secret is safely stored and encrypted in the Secrets Manager in your site's dashboard so that only you can access it. You choose a name for each secret, which is used in your site's code.


What Was Covered:

- Add a Secret

- Add Backend Code for secret

- Add Front-end Code for the secret to being displayed

- Setting up the API

- Test the code using the preview mode

 

Code Snippet to follow along with the video:


Page Code


This imports the wixData API

import {retreiveApi} from 'backend/tutorial';

This loads the Secret that was stored in your Secrets Manager

$w.onReady(function () {
 //TODO: write your page related code here...

    retreiveApi().then((result) => {
        console.log(result) //DO NOT USE THIS FOR YOUR SITE. THIS WILL SHOW VISITORS YOUR SECRET AND YOU DON'T WANT THAT. THIS WAS ONLY FOR TUTORIAL PURPOSES TO RETRIEVE THE SECRET.
    }).catch((err) => {
        console.log(err)
    })

});

Backend Code


This code gets the secret of your choice from the Secrets Manager

// Filename: backend/tutorial.jsw (web modules need to have a .jsw extension)
import {getSecret} from 'wix-secrets-backend';

export async function retreiveApi(){
 const secret = await getSecret('ninotutorials_API');
 return secret 
}
//Use the following code in one of your site's front-end files
//to call the retreiveApi function from backend/tutorial.jsw.

/* 
import {retreiveApi} from 'backend/tutorial';

$w.onReady(function () {
 
    multiply(4,5).then(product => {
        console.log(product);
          // Logs: 20
    })
    .catch(error => {
        console.log(error);
    });
});
*/

 

More Wix Tutorials:

- Wix Tutorials for Beginners

This Wix playlist will have multiple Wix tutorials uploaded EVERY WEEK of 2020! Comment below for any Wix troubles you may have.


- Wix Tutorials 2020


- More playlist here


+ more to come in the future!



Comments


SIGN UP

Get notified of upcoming articles.

Get Started
View More Categories
Images
Animations
Recent Post

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Haga clic aquí para agregar su

propio contenido, o conectarse.

creativelynino_00001.png
YouTube

Did this help?

Yes
No

Thanks, we'll pass on your feedback to improve our services.

Survey
Contact
Feedback

TAKE THE SURVEY

We would love to hear from you.  We strive to create content that is valuable to all persons with and without coding experience.  Please fill out this anonymous survey about your Corvid learning experience.
GET STARTED
bottom of page