Add: insert account data to db
This commit is contained in:
parent
67afe14c02
commit
f20d07905a
|
@ -1,5 +1,5 @@
|
||||||
import { ipcMain, Event, shell, app } from "electron"
|
import { ipcMain, Event, shell, app } from "electron"
|
||||||
import Mastodon, { Status, Response } from "megalodon"
|
import Mastodon, { Response, Account } from "megalodon"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import Datastore from "nedb"
|
import Datastore from "nedb"
|
||||||
import Window from "./Window"
|
import Window from "./Window"
|
||||||
|
@ -33,14 +33,14 @@ export default class Auth {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Window.windowMap.get("main")!.webContents.send(`error`, {
|
event.sender.send(`error`, {
|
||||||
id: "ERROR_GET_AUTHURL",
|
id: "ERROR_GET_AUTHURL",
|
||||||
message: "Failed to get auth URL to login."
|
message: "Failed to get auth URL to login."
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err: Error) =>
|
.catch((err: Error) =>
|
||||||
Window.windowMap.get("main")!.webContents.send(`error`, {
|
event.sender.send(`error`, {
|
||||||
id: "ERROR_CONNECTION",
|
id: "ERROR_CONNECTION",
|
||||||
message: "Connection error",
|
message: "Connection error",
|
||||||
meta: err
|
meta: err
|
||||||
|
@ -60,23 +60,39 @@ export default class Auth {
|
||||||
)
|
)
|
||||||
|
|
||||||
client
|
client
|
||||||
.get<[Status]>("/accounts/verify_credentials")
|
.get<Account>("/accounts/verify_credentials")
|
||||||
.then((resp: Response<[Status]>) => {
|
.then((resp: Response<Account>) => {
|
||||||
console.log(resp.data)
|
let you = resp.data
|
||||||
var db = new Datastore({
|
let db = new Datastore({
|
||||||
filename: join(app.getPath("userData"), "account.db")
|
filename: join(app.getPath("userData"), "account.db"),
|
||||||
|
autoload: true
|
||||||
})
|
})
|
||||||
db.loadDatabase()
|
let docs = {
|
||||||
|
acct: you.acct,
|
||||||
|
avatar: you.avatar,
|
||||||
|
avatarStatic: you.avatar_static,
|
||||||
|
accessToken: tokenData.accessToken
|
||||||
|
}
|
||||||
|
db.insert(docs, function(err, newDocs) {
|
||||||
|
if(err){
|
||||||
|
event.sender.send(`error`, {
|
||||||
|
id: "ERROR_YOU_TRY_ANOTHER_ACCOUNT",
|
||||||
|
message: "You cannot login already logined account."
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
Window.windowMap.get("main")!.webContents.send(`error`, {
|
event.sender.send(`login-complete`, newDocs)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
event.sender.send(`error`, {
|
||||||
id: "ERROR_GET_TOKEN",
|
id: "ERROR_GET_TOKEN",
|
||||||
message: "Failed to get access token."
|
message: "Failed to get access token."
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err: Error) =>
|
.catch((err: Error) =>
|
||||||
Window.windowMap.get("main")!.webContents.send(`error`, {
|
event.sender.send(`error`, {
|
||||||
id: "ERROR_CONNECTION",
|
id: "ERROR_CONNECTION",
|
||||||
message: "Connection error",
|
message: "Connection error",
|
||||||
meta: err
|
meta: err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user