Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Is this code hidden for the client in sveltekit?

Will the api key be hidden from the user?

# $lib/config.js

import { initializeApp } from 'firebase/app';
import { getFirestore } from "firebase/firestore/lite";
        
        
const firebaseConfig = {
      apiKey: "my-key",
};
        
const app = initializeApp(firebaseConfig);
        
export const db = getFirestore(app);


#index.svelte

import {db} from "$lib/config"

db.get...and so on

Trying to understand how to deal with things you want to keep hidden in sveltekit as normally js is visible for the user if wanted through source.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to divide your index.svelte file into 2 parts. Public and providing data.

BTW: Your code suggestion won't work because the code won't always execute on the server (SSR). You cannot access the database in the browser.

index.json.js, always run on server, where you can authenticate user and prepare data. (Read more about endpoints)


import {db} from "$lib/config"

db.get...and so on

index.svelte, where you load prepared data

<script context="module">
    /** @type {import('@sveltejs/kit').Load} */
    export async function load({ params, fetch, session, stuff }) {
        const url = `index.json`;
        const res = await fetch(url);

        if (res.ok) {
            return {
                props: {
                    article: await res.json()
                }
            };
        }

        return {
            status: res.status,
            error: new Error(`Could not load ${url}`)
        };
    }
</script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda