parent
5fd8d0ac23
commit
2f6b0d4cac
|
@ -37,8 +37,16 @@ async function redirectToOauth () {
|
|||
}
|
||||
const redirectUri = getRedirectUri()
|
||||
const registrationPromise = registerApplication(instanceNameInSearch, redirectUri)
|
||||
const instanceInfo = await getInstanceInfo(instanceNameInSearch)
|
||||
await database.setInstanceInfo(instanceNameInSearch, instanceInfo) // cache for later
|
||||
try {
|
||||
const instanceInfo = await getInstanceInfo(instanceNameInSearch)
|
||||
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
|
||||
store.set({
|
||||
currentRegisteredInstanceName: instanceNameInSearch,
|
||||
|
|
|
@ -111,7 +111,11 @@ export async function updateVerifyCredentialsForCurrentInstance () {
|
|||
|
||||
export async function updateInstanceInfo (instanceName) {
|
||||
await cacheFirstUpdateAfter(
|
||||
() => getInstanceInfo(instanceName),
|
||||
() => {
|
||||
const { loggedInInstances } = store.get()
|
||||
const accessToken = loggedInInstances[instanceName] && loggedInInstances[instanceName].access_token
|
||||
return getInstanceInfo(instanceName, accessToken)
|
||||
},
|
||||
() => database.getInstanceInfo(instanceName),
|
||||
info => database.setInstanceInfo(instanceName, info),
|
||||
info => {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
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`
|
||||
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 {
|
||||
async oncreate () {
|
||||
const codeMatch = location.search.match(/code=([^&]+)/)
|
||||
if (codeMatch) {
|
||||
return handleOauthCode(codeMatch[1])
|
||||
const params = new URLSearchParams(location.search)
|
||||
const code = params.get('code')
|
||||
if (code) {
|
||||
await handleOauthCode(code)
|
||||
} else {
|
||||
this.set({
|
||||
hasIndexedDB: await testHasIndexedDB(),
|
||||
hasLocalStorage: testHasLocalStorage()
|
||||
})
|
||||
}
|
||||
this.set({
|
||||
hasIndexedDB: await testHasIndexedDB(),
|
||||
hasLocalStorage: testHasLocalStorage()
|
||||
})
|
||||
},
|
||||
components: {
|
||||
SettingsLayout,
|
||||
|
|
Loading…
Reference in New Issue