Suport de The Movie Database

I am new and trying to fetch data from the API, but I see that both the header method and URL method allow the API key to be exposed. I am trying to figure out how to secure the API key in Next.js with typescript. I know this isn't exactly a TMDB issue but it is relevant. Hoping someone can give me some pointers on how I can fetch the data and display it without showing my api key in inspect element or the URL.

2 resposta (a les p脿gines 1 de 1)

Jump to last post

@matthewevanblu said:
How to secure API key so it's not exposed in Next.js?
I am new and trying to fetch data from the API, but I see that both the header method and URL method allow the API key to be exposed. I am trying to figure out how to secure the API key in Next.js with typescript. I know this isn't exactly a TMDB issue but it is relevant. Hoping someone can give me some pointers on how I can fetch the data and display it without showing my api key in inspect element or the URL.

In order to not expose your API Key, I think it is better to use the Token feature.
I have never used it, so I will be of little help.
But I suggest you read this page in the docs.
https://developer.themoviedb.org/reference/authentication-create-session
https://developer.themoviedb.org/reference/authentication-how-do-i-generate-a-session-id

@matthewevanblu said:

I am new and trying to fetch data from the API, but I see that both the header method and URL method allow the API key to be exposed. I am trying to figure out how to secure the API key in Next.js with typescript. I know this isn't exactly a TMDB issue but it is relevant. Hoping someone can give me some pointers on how I can fetch the data and display it without showing my api key in inspect element or the URL.

Whenever you use APIs with secrets, it is advisable to keep them on the backend. Your backend then serves as something like a proxy between the "real API" and your front-end. With NextJS, this is very easy to accomplish as NextJS allows you to create server components. That means its code remains on the server and the client will not contain it. Thus, keep all code that accesses the TMDB Api on the backend and that way nobody is able to see. You are also able to limit the API calls that way if your own backend manages the amount of calls being made.

No trobeu una pel路l铆cula o una s猫rie? Inicieu la sessi贸 per a crear-la.

Global

s centra la barra de cerca
p obre el men煤 del perfil
esc tanca una finestra oberta
? obre la finestra de dreceres de teclat

A les p脿gines de materials

b torna enrere (o la superior quan sigui aplicable)
e ves a la p脿gina d鈥檈dici贸

A les p脿gines de temporades

(fletxa dreta) ves a la temporada seg眉ent
(fletxa esquerra) ves a la temporada anterior

A les p脿gines d'episodis

(fletxa dreta) ves a l'episodi seg眉ent
(fletxa esquerra) ves a l'episodi anterior

A totes les p脿gines d'imatges

a obre la finestra d'afegir imatges

A totes les p脿gines d'edici贸

t obre el selector de traducci贸
ctrl+ s envia el formulari

A les p脿gines de debat

n crea un debat nou
w canvia l'estat de visualitzaci贸
p canvia p煤blic/privat
c tanca o obre
a obre activitat
r resposta al debat
l ves a la darrera resposta
ctrl+ enter envieu el vostre missatge
(fletxa dreta) p脿gina seg眉ent
(fletxa esquerra) p脿gina anterior

Configuracions

Desitgeu valorar o afegir aquest element a una llista?

Inicieu la sessi贸