diff --git a/src/renderer/store/Authorize.ts b/src/renderer/store/Authorize.ts index 9a64fee5..262cb489 100644 --- a/src/renderer/store/Authorize.ts +++ b/src/renderer/store/Authorize.ts @@ -9,7 +9,7 @@ const state = (): AuthorizeState => ({}) const actions: ActionTree = { submit: (_, code: string) => { return new Promise((resolve, reject) => { - ipcRenderer.send('get-access-token', code) + ipcRenderer.send('get-access-token', code.trim()) ipcRenderer.once('response-get-access-token', (_, id: string) => { ipcRenderer.removeAllListeners('error-get-access-token') resolve(id) diff --git a/src/renderer/store/Login.ts b/src/renderer/store/Login.ts index 1750f267..a1f4d6a9 100644 --- a/src/renderer/store/Login.ts +++ b/src/renderer/store/Login.ts @@ -46,13 +46,14 @@ const actions: ActionTree = { }, confirmInstance: async ({ commit, rootState }, domain: string): Promise => { commit(MUTATION_TYPES.CHANGE_SEARCHING, true) + const cleanDomain = domain.trim() try { - await Mastodon.get('/api/v1/instance', {}, `https://${domain}`, rootState.App.proxyConfiguration) + await Mastodon.get('/api/v1/instance', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration) commit(MUTATION_TYPES.CHANGE_SEARCHING, false) } catch (err) { // https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8 // Check /.well-known/host-meta to confirm mastodon instance. - const res = await Mastodon.get('/.well-known/host-meta', {}, `https://${domain}`, rootState.App.proxyConfiguration).finally( + const res = await Mastodon.get('/.well-known/host-meta', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration).finally( () => { commit(MUTATION_TYPES.CHANGE_SEARCHING, false) } @@ -60,11 +61,11 @@ const actions: ActionTree = { const parser = new DOMParser() const dom = parser.parseFromString(res.data, 'text/xml') const link = dom.getElementsByTagName('Link')[0].outerHTML - if (!link.includes(`https://${domain}/.well-known/webfinger`)) { + if (!link.includes(`https://${cleanDomain}/.well-known/webfinger`)) { throw new Error('domain is not activity pub') } } - commit(MUTATION_TYPES.CHANGE_INSTANCE, domain) + commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain) return true } }