Add: get verify_credentials and error message
This commit is contained in:
parent
8f3edf76e6
commit
41bc02c959
|
@ -1,5 +1,6 @@
|
|||
import { ipcMain, Event, shell } from "electron"
|
||||
import Mastodon from "megalodon"
|
||||
import Mastodon, { Status, Response } from "megalodon"
|
||||
import Window from "./Window"
|
||||
|
||||
export default class Auth {
|
||||
public static ready() {
|
||||
|
@ -14,7 +15,8 @@ export default class Auth {
|
|||
scopes: SCOPES
|
||||
},
|
||||
"https://" + instance
|
||||
).then(appData => {
|
||||
)
|
||||
.then(appData => {
|
||||
clientId = appData.clientId
|
||||
clientSecret = appData.clientSecret
|
||||
url = appData.url
|
||||
|
@ -29,17 +31,60 @@ export default class Auth {
|
|||
}
|
||||
)
|
||||
} else {
|
||||
console.log(appData)
|
||||
Window.windowMap
|
||||
.get("main")!
|
||||
.webContents.send(`error`, {
|
||||
id: "ERROR_GET_AUTHURL",
|
||||
message: "Failed to get auth URL to login."
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((err: Error) => console.error(err))
|
||||
.catch((err: Error) =>
|
||||
Window.windowMap
|
||||
.get("main")!
|
||||
.webContents.send(`error`, {
|
||||
id: "ERROR_CONNECTION",
|
||||
message: "Connection error",
|
||||
meta: err
|
||||
})
|
||||
ipcMain.on("new-account-auth", async (event: Event, code: string, instance: string) => {
|
||||
Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance)
|
||||
)
|
||||
})
|
||||
ipcMain.on(
|
||||
"new-account-auth",
|
||||
async (event: Event, code: string, instance: string) => {
|
||||
let url: string = "https://" + instance
|
||||
Mastodon.fetchAccessToken(clientId, clientSecret, code, url)
|
||||
.then((tokenData: Partial<{ accessToken: string }>) => {
|
||||
console.log(tokenData.accessToken)
|
||||
if (tokenData.accessToken) {
|
||||
const client = new Mastodon(
|
||||
tokenData.accessToken,
|
||||
url + "/api/v1"
|
||||
)
|
||||
|
||||
client
|
||||
.get<[Status]>("/accounts/verify_credentials")
|
||||
.then((resp: Response<[Status]>) => {
|
||||
console.log(resp.data)
|
||||
})
|
||||
.catch((err: Error) => console.error(err))
|
||||
} else {
|
||||
Window.windowMap
|
||||
.get("main")!
|
||||
.webContents.send(`error`, {
|
||||
id: "ERROR_GET_TOKEN",
|
||||
message: "Failed to get access token."
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((err: Error) =>
|
||||
Window.windowMap
|
||||
.get("main")!
|
||||
.webContents.send(`error`, {
|
||||
id: "ERROR_CONNECTION",
|
||||
message: "Connection error",
|
||||
meta: err
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user