mirror of
https://github.com/tribufu/tribufu-js
synced 2026-06-01 09:42:36 +00:00
Update TribufuClient.fromEnv()
Also read apiKey from env
This commit is contained in:
parent
db6a2cd5da
commit
23dac26596
1 changed files with 11 additions and 4 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue