fix: error msg when logging in to same instance (#735)

This commit is contained in:
Nolan Lawson 2018-12-05 21:34:02 -08:00 committed by GitHub
parent f7164dd4c0
commit c0f857336a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,8 +14,9 @@ async function redirectToOauth () {
let { instanceNameInSearch, loggedInInstances } = store.get() let { instanceNameInSearch, loggedInInstances } = store.get()
instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase()
if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) { if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) {
store.set({ logInToInstanceError: `You've already logged in to ${instanceNameInSearch}` }) let err = new Error(`You've already logged in to ${instanceNameInSearch}`)
return err.knownError = true
throw err
} }
let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI) let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI)
let instanceInfo = await getInstanceInfo(instanceNameInSearch) let instanceInfo = await getInstanceInfo(instanceNameInSearch)
@ -44,10 +45,10 @@ export async function logInToInstance () {
} catch (err) { } catch (err) {
console.error(err) console.error(err)
let error = `${err.message || err.name}. ` + let error = `${err.message || err.name}. ` +
(navigator.onLine (err.knownError ? '' : (navigator.onLine
? `Is this a valid Mastodon instance? Is a browser extension ? `Is this a valid Mastodon instance? Is a browser extension
blocking the request? Are you in private browsing mode?` blocking the request? Are you in private browsing mode?`
: `Are you offline?`) : `Are you offline?`))
let { instanceNameInSearch } = store.get() let { instanceNameInSearch } = store.get()
store.set({ store.set({
logInToInstanceError: error, logInToInstanceError: error,