Text input / password and Get secret?

Hello, I’m fairly new as you can see from my questions and no background on these topics, but I would want to combine simple text input as password, and if user enters correct password it would be matched with getsecret().
I have like 120 apikeys which are predefined and they would be matched with user provided inputs as I tried to describe above.

There is no sensitive information behind password restricted page/no user info whatsoever but only a simple poll. So for that reason I have selected this approach.
So my problem is to combine two export functions below

export async function getSecret () {
const mySecret = await getSecret ( “secret_1” );
return mySecret
}

//so if input1 is matched with any of secret1-secret120, it would grant access to page …/1

export function button1_click ( event ) {
if ( $w ( “#input1” ). value == ( “X01002” ). toString ())
wixLocation . to ( “/1” )

}

What to do? And sorry, instead of “X01002” should be mySecret most likely

You should use a database collection instead.

But if you wish to continue with secret keys, you can run:
backend/keys.js w :

import wixSecretsBackend from 'wix-secrets-backend';
export function getSecret (value) {
    return getSecret(value).then(secret => {
    if(!secret){return Promise.reject('no-match');}
    return secret;
    })
    .catch(err => err);
}

FRONT END:

import wixLocation from 'wix-location';
import { getSecret } from 'backend/keys.jsw';
export function button1_click(event) {
getSecret($w('#input1').value)
.then(() => wixLocation.to('/1'));
}

[UPDATED]

Hello and thank you for your answer.

// “)” missing after no-match?
Backend is:

import wixSecretsBackend from 'wix-secrets-backend';
export function getSecret (value) {
    return getSecret(value).then(secret => {
    if(!secret){return Promise.reject('no-match');}
    return secret;
    })
    .catch(err => err);
}

All seems to be in place, but wixLocation is highlighted and cannot be found.

import { getSecret } from 'backend/keys.jsw';
export function button1_click(event) {
getSecret($w('#input1').value)
//this ->
.then(() => wixLocation.to("/1")); 
}

Is this missing in Frontend

import wixLocation from 'wix-location'; 
$w.onReady(function () { 
});

?
No clue how to add it to abovementioned

@allekhius I updated the code. But it’ll find the secret only if the user types the secret name. Otherwise you’ll have to use database collection.

@jonatandor35 Yeah, it does not seems to work plus if user has to type the name, its not worth the use … any examples how database collection would work? thanks for the effort anyways

@allekhius

https://www.wix.com/velo/reference/wix-data