diff --git a/src/components/Preference/AccountManager.vue b/src/components/Preference/AccountManager.vue index 5c8358b9..e0a8e15a 100644 --- a/src/components/Preference/AccountManager.vue +++ b/src/components/Preference/AccountManager.vue @@ -26,6 +26,7 @@ type Instance = string export default class Auth extends Vue { public instance: Instance = "" public inputCode: boolean = false + public code: string public get hasDomain() { return this.instance != "" } @@ -37,7 +38,7 @@ export default class Auth extends Vue { public authCode() { let code = this.code this.inputCode = true - ipcRenderer.send(`new-account-setup`, target) + ipcRenderer.send(`new-account-auth`, code, this.instance) } } diff --git a/src/main/Auth.ts b/src/main/Auth.ts index 0ed3fff2..a6d87308 100644 --- a/src/main/Auth.ts +++ b/src/main/Auth.ts @@ -3,36 +3,42 @@ import Mastodon from "megalodon" export default class Auth { public static ready() { + let clientId: string + let clientSecret: string ipcMain.on("new-account-setup", async (event: Event, instance: string) => { const SCOPES: string = "read write follow" - let clientId: string - let clientSecret: string let url: string | null Mastodon.registerApp( "TheDesk", { scopes: SCOPES }, - "https://"+instance + "https://" + instance ).then(appData => { clientId = appData.clientId clientSecret = appData.clientSecret url = appData.url - if(url){ - shell.openExternal( - url, - { - activate: false - }, - err => { - if (err) console.log(err) - } - ) - }else{ - console.log(appData) + if (url) { + shell.openExternal( + url, + { + activate: false + }, + err => { + if (err) console.log(err) + } + ) + } else { + console.log(appData) } - }) }) + ipcMain.on("new-account-auth", async (event: Event, code: string, instance: string) => { + Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://"+instance) + .then((tokenData: Partial<{ accessToken: string }>) => { + console.log(tokenData.accessToken) + }) + .catch((err: Error) => console.error(err)) + }) } }