How Do I Obscure API Keys On The Client? (2024)

Question: How do I obscure API keys on the client?

Answer: So you have a super powerful key to a 3rd party API that allows you to read/write any data you want from any customer, and you don’t want that falling into anyone else’s hands. What do you do? Gotcha. First off, you never send that to the client, not in any way, not obscured, not encrypted, not anything. Because try as you might to hide it, the key will end up showing clear as day in the Network tab of the Inspector as soon as you make a call on the client.

How Do I Obscure API Keys On The Client? (2)

What you should do instead is create a proxy API endpoint on your NextJS server. NextJS has always had great support for making API routes. You can use a route handler to create a proxy endpoint that will take the request from the client, and then make the request to the 3rd party API on the server. This way, the client never sees the API key, and you can do whatever you want with the response before sending it back to the client.

This proxy API also doesn’t need to be a 1-to-1 proxy, you can create an abstraction layer that allows you to do things like caching, or rate limiting, or even just to make the API easier to use. For example, if you have a 3rd party API that requires you to make 3 separate calls to get the data you need, you can create a single endpoint that makes those 3 calls and returns the data in a single response. In addition this new API ensures that if you want to change out that 3rd party API layer later that you only have to change it in one place.

To be honest, learning how to make the calls from a NextJS route handler will teach you how to make the calls to the API during Server Side Rendering, which is probably what you want to do anyway. So learning this technique of building proxy APIs is a two-fer!

Before you do any of this, make sure that the API key is indeed dangerous to be on client. Not all API keys are meant to be kept secret. Some keys, like Firebase keys, are meant to be used on the client. If you’re not sure, check the documentation for the API you’re using.

Jack Herrington is currently working on a course on NextJS, subscribe to the newsletter to get updates as well as React and NextJS tips, tricks and tutorials.

How Do I Obscure API Keys On The Client? (2024)
Top Articles
Generating and Using API Tokens
How much of your paycheck should you save?
Poe T4 Aisling
Minooka Channahon Patch
Melson Funeral Services Obituaries
Odawa Hypixel
Craftsman M230 Lawn Mower Oil Change
News - Rachel Stevens at RachelStevens.com
His Lost Lycan Luna Chapter 5
Emmalangevin Fanhouse Leak
Tlc Africa Deaths 2021
Which Is A Popular Southern Hemisphere Destination Microsoft Rewards
12 Best Craigslist Apps for Android and iOS (2024)
Edible Arrangements Keller
Skylar Vox Bra Size
Bjork & Zhulkie Funeral Home Obituaries
Five Day National Weather Forecast
Conan Exiles Thrall Master Build: Best Attributes, Armor, Skills, More
Chastity Brainwash
Beebe Portal Athena
Walmart stores in 6 states no longer provide single-use bags at checkout: Which states are next?
Hocus Pocus Showtimes Near Amstar Cinema 16 - Macon
Golden Abyss - Chapter 5 - Lunar_Angel
Bridge.trihealth
Empire Visionworks The Crossings Clifton Park Photos
Melendez Imports Menu
Dark Entreaty Ffxiv
Jordan Poyer Wiki
Integer Division Matlab
Wiseloan Login
Sienna
Criterion Dryer Review
Pixel Combat Unblocked
Healthy Kaiserpermanente Org Sign On
Delta Math Login With Google
LG UN90 65" 4K Smart UHD TV - 65UN9000AUJ | LG CA
Vip Lounge Odu
Restaurants Near Calvary Cemetery
L'alternativa - co*cktail Bar On The Pier
The 50 Best Albums of 2023
Los Garroberros Menu
Www Craigslist Com Brooklyn
Vocabulary Workshop Level B Unit 13 Choosing The Right Word
Updates on removal of DePaul encampment | Press Releases | News | Newsroom
Tricia Vacanti Obituary
Levi Ackerman Tattoo Ideas
Honkai Star Rail Aha Stuffed Toy
How To Get To Ultra Space Pixelmon
Paperlessemployee/Dollartree
Booknet.com Contract Marriage 2
Used Auto Parts in Houston 77013 | LKQ Pick Your Part
Latest Posts
Article information

Author: Kimberely Baumbach CPA

Last Updated:

Views: 5990

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kimberely Baumbach CPA

Birthday: 1996-01-14

Address: 8381 Boyce Course, Imeldachester, ND 74681

Phone: +3571286597580

Job: Product Banking Analyst

Hobby: Cosplaying, Inline skating, Amateur radio, Baton twirling, Mountaineering, Flying, Archery

Introduction: My name is Kimberely Baumbach CPA, I am a gorgeous, bright, charming, encouraging, zealous, lively, good person who loves writing and wants to share my knowledge and understanding with you.