fix: add instance blocks (#1326)
* fix: add instance blocks * block domains, not just instances
This commit is contained in:
parent
ade28cca5d
commit
6b40b2efbf
|
@ -6,17 +6,25 @@ import { store } from '../_store/store'
|
|||
import { updateVerifyCredentialsForInstance } from './instances'
|
||||
import { updateCustomEmojiForInstance } from './emoji'
|
||||
import { database } from '../_database/database'
|
||||
import { DOMAIN_BLOCKS } from '../_static/blocks'
|
||||
|
||||
const REDIRECT_URI = (typeof location !== 'undefined'
|
||||
? location.origin : 'https://pinafore.social') + '/settings/instances/add'
|
||||
|
||||
function createKnownError (message) {
|
||||
let err = new Error(message)
|
||||
err.knownError = true
|
||||
return err
|
||||
}
|
||||
|
||||
async function redirectToOauth () {
|
||||
let { instanceNameInSearch, loggedInInstances } = store.get()
|
||||
instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase()
|
||||
instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/+$/, '').toLowerCase()
|
||||
if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) {
|
||||
let err = new Error(`You've already logged in to ${instanceNameInSearch}`)
|
||||
err.knownError = true
|
||||
throw err
|
||||
throw createKnownError(`You've already logged in to ${instanceNameInSearch}`)
|
||||
}
|
||||
if (DOMAIN_BLOCKS.some(domain => new RegExp(`(?:\\.|^)${domain}$`, 'i').test(instanceNameInSearch))) {
|
||||
throw createKnownError('This service is blocked')
|
||||
}
|
||||
let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI)
|
||||
let instanceInfo = await getInstanceInfo(instanceNameInSearch)
|
||||
|
|
|
@ -112,6 +112,7 @@
|
|||
methods: {
|
||||
onSubmit (event) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
logInToInstance()
|
||||
}
|
||||
}
|
||||
|
|
4
src/routes/_static/blocks.js
Normal file
4
src/routes/_static/blocks.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const DOMAIN_BLOCKS = [
|
||||
'gab.com',
|
||||
'gab.ai'
|
||||
]
|
Loading…
Reference in a new issue