mirror of
https://github.com/tribufu/sdk-js
synced 2025-06-16 10:44:17 +00:00
Update TribufuClient.fromEnv()
Also read apiKey from env
This commit is contained in:
@ -40,14 +40,21 @@ export class TribufuClient extends TribufuApi {
|
|||||||
*/
|
*/
|
||||||
public static override fromEnv(prefix?: string | null): TribufuClient | null {
|
public static override fromEnv(prefix?: string | null): TribufuClient | null {
|
||||||
const envPrefix = prefix ? `${prefix}_` : "";
|
const envPrefix = prefix ? `${prefix}_` : "";
|
||||||
|
const apiKey = process.env[`${envPrefix}API_KEY`];
|
||||||
const clientId = process.env[`${envPrefix}CLIENT_ID`];
|
const clientId = process.env[`${envPrefix}CLIENT_ID`];
|
||||||
const clientSecret = process.env[`${envPrefix}CLIENT_SECRET`];
|
const clientSecret = process.env[`${envPrefix}CLIENT_SECRET`];
|
||||||
|
|
||||||
if (clientId && clientSecret) {
|
if (!clientId || !clientSecret) {
|
||||||
return new TribufuClient(clientId, clientSecret);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
const client = new TribufuClient(clientId, clientSecret);
|
||||||
|
|
||||||
|
if (apiKey) {
|
||||||
|
client.setApiKey(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +79,7 @@ export class TribufuClient extends TribufuApi {
|
|||||||
const accessToken = cookies["access_token"] || null;
|
const accessToken = cookies["access_token"] || null;
|
||||||
const refreshToken = cookies["refresh_token"] || null;
|
const refreshToken = cookies["refresh_token"] || null;
|
||||||
|
|
||||||
if (client) {
|
if (client && accessToken && refreshToken) {
|
||||||
client.setTokens(accessToken, refreshToken);
|
client.setTokens(accessToken, refreshToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user