1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-05 23:40:12 +01:00
pingvin-share/.setup/services/auth.service.ts

46 lines
1023 B
TypeScript
Raw Normal View History

2022-04-25 15:15:17 +02:00
import api from "./api.service";
import rl from "readline-sync";
import cookie from "cookie";
const getToken = async () => {
2022-05-12 21:48:37 +02:00
console.info("Please enter your Appwrite credentials");
2022-04-25 15:15:17 +02:00
var email = rl.question("Email: ");
var password = rl.question("Password: ", {
hideEchoBack: true,
});
const credentials = await api().post("/account/sessions", {
email,
password,
});
return cookie.parse(credentials.headers["set-cookie"].toString())
.a_session_console_legacy;
};
const generateApiKey = async () => {
const res = await api().post("/projects/pingvin-share/keys", {
name: "Setup key",
scopes: [
"collections.read",
"collections.write",
"attributes.read",
"attributes.write",
"indexes.read",
"indexes.write",
"documents.read",
"documents.write",
"functions.read",
"functions.write",
"execution.read",
"execution.write",
],
});
return res.data.secret;
};
export default {
getToken,
generateApiKey,
};