question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I send secure API requests from SvelteKit app, without showing API keys on the client side?

See original GitHub issue

I’m using Supabase for a new Sveltekit app, with this template (https://github.com/joshnuss/svelte-supabase)

Currently, I’m passing the Supabase keys through on the client side, like this:

const supabase = createClient(
  import.meta.env.VITE_SUPABASE_URL,
  import.meta.env.VITE_SUPABASE_ANON_KEY
)

What is the simplest way that I can create a secure backend/API, so the application can fetch content from Supabase, without showing Supabase key on the client side?

Is there any functionality built into Sveltekit that enables me to do this? Or would I need to integrate a backend like Rails?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
dominikgcommented, May 17, 2021

enabling github discussions could also be an option

2reactions
lsabicommented, Jun 8, 2021

@AleCandido it doesn’t matter if it’s static or dynamic. In order to generate a static website, you need to run the whole app and get the pages. In order to get the pages you have to perform the request to the API. In my case I was forwarding the requests via a middleware and adding the secret API key.

That’s why I was confused and would like the docs to describe it in details. The middleware was a really nice thing to have in sapper and can slow down the development/transition to kit.

I solved my problem with an endpoint that forwards every request, though it doesn’t feel the right approach…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I send secure API requests from SvelteKit app ...
What is the simplest way that I can create a secure backend/API, so the application can fetch content from Supabase, without showing Supabase ......
Read more >
Types • Docs • SvelteKit
internal requests (e.g. for +server.js routes) go directly to the handler function when running on the server, without the overhead of an HTTP...
Read more >
How to avoid exposing your API key in your public front-end ...
The Problem All you want to do is fetch some JSON from an API endpoint for ... that can send the appropriate POST...
Read more >
API Routes/Endpoints in SvelteKit - YouTube
If you find my content useful and want to support the channel, you can now become a channel member! https://hbyt.us/joinSvelteKit is a ...
Read more >
Migrating Breaking Changes in SvelteKit - Netlify
js that will only run on the server making it safe for API keys and secure SDKs you don't want leaked to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found