External auth: normalize instance
This commit is contained in:
parent
58466ce79c
commit
9c0a304926
|
@ -6,11 +6,10 @@
|
||||||
* @see module:soapbox/actions/oauth
|
* @see module:soapbox/actions/oauth
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
||||||
|
|
||||||
import { createApp } from 'soapbox/actions/apps';
|
import { createApp } from 'soapbox/actions/apps';
|
||||||
import { authLoggedIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth';
|
import { authLoggedIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth';
|
||||||
import { obtainOAuthToken } from 'soapbox/actions/oauth';
|
import { obtainOAuthToken } from 'soapbox/actions/oauth';
|
||||||
|
import { normalizeInstance } from 'soapbox/normalizers';
|
||||||
import { parseBaseURL } from 'soapbox/utils/auth';
|
import { parseBaseURL } from 'soapbox/utils/auth';
|
||||||
import sourceCode from 'soapbox/utils/code';
|
import sourceCode from 'soapbox/utils/code';
|
||||||
import { getWalletAndSign } from 'soapbox/utils/ethereum';
|
import { getWalletAndSign } from 'soapbox/utils/ethereum';
|
||||||
|
@ -22,12 +21,12 @@ import { baseClient } from '../api';
|
||||||
const fetchExternalInstance = baseURL => {
|
const fetchExternalInstance = baseURL => {
|
||||||
return baseClient(null, baseURL)
|
return baseClient(null, baseURL)
|
||||||
.get('/api/v1/instance')
|
.get('/api/v1/instance')
|
||||||
.then(({ data: instance }) => fromJS(instance))
|
.then(({ data: instance }) => normalizeInstance(instance))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
// Authenticated fetch is enabled.
|
// Authenticated fetch is enabled.
|
||||||
// Continue with a limited featureset.
|
// Continue with a limited featureset.
|
||||||
return ImmutableMap({ version: '0.0.0' });
|
return normalizeInstance({});
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue