feat: Allow changing instance URL when not logged in
This commit is contained in:
1 parent
f127b5f645
commit
fed5cc2263
11 files changed
+133
-76
No files matched your search
@@ -8,7 +8,12 @@
|
||||
addToast,
|
||||
toast,
|
||||
} from '$lib/components/ui/toasts/toasts.js'
|
||||
import { DEFAULT_INSTANCE_URL, authData, getClient } from '$lib/lemmy.js'
|
||||
import {
|
||||
DEFAULT_INSTANCE_URL,
|
||||
authData,
|
||||
getClient,
|
||||
validateInstance,
|
||||
} from '$lib/lemmy.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
|
||||
let data = {
|
||||
@@ -19,22 +24,10 @@
|
||||
loading: false,
|
||||
}
|
||||
|
||||
async function validateURL(instance: string): Promise<boolean> {
|
||||
if (instance == '') return false
|
||||
|
||||
try {
|
||||
await getClient(instance).getSite({})
|
||||
} catch (err) {
|
||||
throw new Error('Failed to contact that instance. Is it down?')
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async function logIn() {
|
||||
data.loading = true
|
||||
try {
|
||||
if (!(await validateURL(data.instance))) {
|
||||
if (!(await validateInstance(data.instance))) {
|
||||
throw new Error('Failed to contact that instance. Is it down?')
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user