TMDB supports two authentication methods. Pass either directly to the TMDB constructor.
Obtain a read access token from TMDB API Settings under "API Read Access Token".
import { TMDB } from '@api-wrappers/tmdb-wrapper';
const tmdb = new TMDB('YOUR_READ_ACCESS_TOKEN');The token is sent as a Bearer token in the Authorization header on every request.
const tmdb = new TMDB({ apiKey: 'YOUR_API_KEY' });The API key is appended as the api_key query parameter.
You can provide both. The access token takes precedence for the Authorization header; the API key is added as a query parameter only when present.
const tmdb = new TMDB({
accessToken: 'YOUR_READ_ACCESS_TOKEN',
apiKey: 'YOUR_API_KEY',
});Never commit credentials to source control. Use environment variables:
const tmdb = new TMDB(process.env.TMDB_ACCESS_TOKEN!);type TMDBConfig =
{
accessToken?: string;
apiKey?: string;
client?: TMDBClientConfig;
};
type TokenType = string | TMDBConfig;