No it doesn’t. We have a new code now, but it’s still not working We can’t find out what the problem is…
import wixSecretsBackend from ‘wix-secrets-backend’ ;
import { fetch } from ‘wix-fetch’ ;
import { btoa , atob } from ‘Base64’ ;
export function getKey ( ) {
return wixSecretsBackend . getSecret ( “key” )
. then (( secret ) => {
let key = “:” + secret ;
return key ;
})
. catch (( error ) => {
console . error ( error );
});
}
export function getUser ( ) {
return wixSecretsBackend . getSecret ( “user” )
. then (( secret ) => {
let key = secret ;
return key ;
})
. catch (( error ) => {
console . error ( error );
});
}
export function encodeKeys ( user , key ) {
let encodedSecret = btoa ( user + key );
return encodedSecret ;
}
export async function doFetch ( ) {
const user = await getUser ();
const key = await getKey ();
const encodedSecret = await encodeKeys ( user , key );
const endpointUrl = “someurl” ;
**return** fetch ( endpointUrl , {
"method" : "get" ,
"headers" : {
"Authorization" : 'Basic ' + encodedSecret ,
"Content-Type" : "application/json"
}
})
. then (( httpResponse ) => {
console . log ( "httpResponse:" , httpResponse );
**if** ( httpResponse . ok ) {
**return** httpResponse . json ();
} **else** {
console . log ( "httpResponse:" , httpResponse );
**return** Promise . reject ( "Fetch did not succeed" );
}
})
. then (( json ) => {
**return** json
})
. **catch** ( err => console . log ( err ));
}