parent
5fd8d0ac23
commit
69bb849508
|
@ -37,8 +37,16 @@ async function redirectToOauth () {
|
||||||
}
|
}
|
||||||
const redirectUri = getRedirectUri()
|
const redirectUri = getRedirectUri()
|
||||||
const registrationPromise = registerApplication(instanceNameInSearch, redirectUri)
|
const registrationPromise = registerApplication(instanceNameInSearch, redirectUri)
|
||||||
|
try {
|
||||||
const instanceInfo = await getInstanceInfo(instanceNameInSearch)
|
const instanceInfo = await getInstanceInfo(instanceNameInSearch)
|
||||||
await database.setInstanceInfo(instanceNameInSearch, instanceInfo) // cache for later
|
await database.setInstanceInfo(instanceNameInSearch, instanceInfo) // cache for later
|
||||||
|
} catch (err) {
|
||||||
|
// We get a 401 in limited federation mode, so we can just skip setting the instance info in that case.
|
||||||
|
// It will be fetched automatically later.
|
||||||
|
if (err.status !== 401) {
|
||||||
|
throw err // this is a good way to test for typos in the instance name or some other problem
|
||||||
|
}
|
||||||
|
}
|
||||||
const instanceData = await registrationPromise
|
const instanceData = await registrationPromise
|
||||||
store.set({
|
store.set({
|
||||||
currentRegisteredInstanceName: instanceNameInSearch,
|
currentRegisteredInstanceName: instanceNameInSearch,
|
||||||
|
|
|
@ -111,7 +111,11 @@ export async function updateVerifyCredentialsForCurrentInstance () {
|
||||||
|
|
||||||
export async function updateInstanceInfo (instanceName) {
|
export async function updateInstanceInfo (instanceName) {
|
||||||
await cacheFirstUpdateAfter(
|
await cacheFirstUpdateAfter(
|
||||||
() => getInstanceInfo(instanceName),
|
() => {
|
||||||
|
const { loggedInInstances } = store.get()
|
||||||
|
const accessToken = loggedInInstances[instanceName] && loggedInInstances[instanceName].access_token
|
||||||
|
return getInstanceInfo(instanceName, accessToken)
|
||||||
|
},
|
||||||
() => database.getInstanceInfo(instanceName),
|
() => database.getInstanceInfo(instanceName),
|
||||||
info => database.setInstanceInfo(instanceName, info),
|
info => database.setInstanceInfo(instanceName, info),
|
||||||
info => {
|
info => {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { get, DEFAULT_TIMEOUT } from '../_utils/ajax.js'
|
import { get, DEFAULT_TIMEOUT } from '../_utils/ajax.js'
|
||||||
import { basename } from './utils.js'
|
import { auth, basename } from './utils.js'
|
||||||
|
|
||||||
export function getInstanceInfo (instanceName) {
|
export function getInstanceInfo (instanceName, accessToken) {
|
||||||
const url = `${basename(instanceName)}/api/v1/instance`
|
const url = `${basename(instanceName)}/api/v1/instance`
|
||||||
return get(url, null, { timeout: DEFAULT_TIMEOUT })
|
// accessToken is required in limited federation mode, but elsewhere we don't need it (e.g. during login)
|
||||||
|
const headers = accessToken ? auth(accessToken) : null
|
||||||
|
return get(url, headers, { timeout: DEFAULT_TIMEOUT })
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,14 +89,16 @@
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async oncreate () {
|
async oncreate () {
|
||||||
const codeMatch = location.search.match(/code=([^&]+)/)
|
const params = new URLSearchParams(location.search)
|
||||||
if (codeMatch) {
|
const code = params.get('code')
|
||||||
return handleOauthCode(codeMatch[1])
|
if (code) {
|
||||||
}
|
await handleOauthCode(code)
|
||||||
|
} else {
|
||||||
this.set({
|
this.set({
|
||||||
hasIndexedDB: await testHasIndexedDB(),
|
hasIndexedDB: await testHasIndexedDB(),
|
||||||
hasLocalStorage: testHasLocalStorage()
|
hasLocalStorage: testHasLocalStorage()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
SettingsLayout,
|
SettingsLayout,
|
||||||
|
|
Loading…
Reference in New Issue