pass x-lbry-auth-token to apis status call for email verified users
This commit is contained in:
parent
cffc70fb6b
commit
b0026a562a
2 changed files with 27 additions and 23 deletions
|
@ -289,7 +289,7 @@ function App(props: Props) {
|
||||||
}, [hasVerifiedEmail, signIn, hasSignedIn]);
|
}, [hasVerifiedEmail, signIn, hasSignedIn]);
|
||||||
|
|
||||||
// @if TARGET='web'
|
// @if TARGET='web'
|
||||||
useDegradedPerformance(setLbryTvApiStatus);
|
useDegradedPerformance(setLbryTvApiStatus, user);
|
||||||
// @endif
|
// @endif
|
||||||
|
|
||||||
// @if TARGET='web'
|
// @if TARGET='web'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { SDK_API_PATH } from 'ui';
|
import { SDK_API_PATH } from 'ui';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
// import { getAuthToken } from 'util/saved-passwords';
|
import { getAuthToken } from 'util/saved-passwords';
|
||||||
// import { X_LBRY_AUTH_TOKEN } from 'constants/token';
|
import { X_LBRY_AUTH_TOKEN } from 'constants/token';
|
||||||
|
|
||||||
import fetchWithTimeout from 'util/fetch';
|
import fetchWithTimeout from 'util/fetch';
|
||||||
|
|
||||||
|
@ -11,23 +11,26 @@ export const STATUS_DEGRADED = 'degraded';
|
||||||
export const STATUS_FAILING = 'failing';
|
export const STATUS_FAILING = 'failing';
|
||||||
export const STATUS_DOWN = 'down';
|
export const STATUS_DOWN = 'down';
|
||||||
|
|
||||||
const getParams = () => {
|
const getParams = user => {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
// const token = getAuthToken();
|
const token = getAuthToken();
|
||||||
// if (token) {
|
if (token && user.has_verified_email) {
|
||||||
// headers[X_LBRY_AUTH_TOKEN] = token;
|
headers[X_LBRY_AUTH_TOKEN] = token;
|
||||||
// }
|
}
|
||||||
const params = { headers };
|
const params = { headers };
|
||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useDegradedPerformance(onDegradedPerformanceCallback) {
|
export function useDegradedPerformance(onDegradedPerformanceCallback, user) {
|
||||||
|
const hasUser = user !== undefined;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (hasUser) {
|
||||||
// The status endpoint is the only endpoint at "v2" currently
|
// The status endpoint is the only endpoint at "v2" currently
|
||||||
// This should be moved into the config once more endpoints are using it
|
// This should be moved into the config once more endpoints are using it
|
||||||
const STATUS_ENDPOINT = `${SDK_API_PATH}/status`.replace('v1', 'v2');
|
const STATUS_ENDPOINT = `${SDK_API_PATH}/status`.replace('v1', 'v2');
|
||||||
|
|
||||||
fetchWithTimeout(STATUS_TIMEOUT_LIMIT, fetch(STATUS_ENDPOINT, getParams()))
|
fetchWithTimeout(STATUS_TIMEOUT_LIMIT, fetch(STATUS_ENDPOINT, getParams(user)))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(status => {
|
.then(status => {
|
||||||
if (status.general_state !== STATUS_OK) {
|
if (status.general_state !== STATUS_OK) {
|
||||||
|
@ -37,5 +40,6 @@ export function useDegradedPerformance(onDegradedPerformanceCallback) {
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
onDegradedPerformanceCallback(STATUS_FAILING);
|
onDegradedPerformanceCallback(STATUS_FAILING);
|
||||||
});
|
});
|
||||||
}, []);
|
}
|
||||||
|
}, [hasUser]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue