1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-10-01 09:00:12 +02:00
pingvin-share/.setup/services/auth.service.ts

46 lines
1.0 KiB
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 16:25:34 +02:00
console.info("Please enter your Appwrite credentials \n");
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,
};