diff --git a/components/collections/import-export-collections.vue b/components/collections/import-export-collections.vue index 20d583c90..0dccae664 100644 --- a/components/collections/import-export-collections.vue +++ b/components/collections/import-export-collections.vue @@ -6,6 +6,35 @@

{{ $t("import_export") }} {{ $t("collections") }}

+ + + + @@ -97,6 +126,37 @@ export default { }, }, methods: { + async createCollectionGist() { + await this.$axios + .$post( + "https://api.github.com/gists", + { + files: { + "hoppscotch-collections.json": { + content: this.collectionJson, + }, + }, + }, + { + headers: { + Authorization: `token ${this.$store.state.postwoman.providerInfo.accessToken}`, + Accept: "application/vnd.github.v3+json", + }, + } + ) + .then((response) => { + this.$toast.success(this.$t("gist_created"), { + icon: "done", + }) + window.open(response.html_url) + }) + .catch((error) => { + this.$toast.error(this.$t("something_went_wrong"), { + icon: "error", + }) + console.log(error) + }) + }, hideModal() { this.$emit("hide-modal") }, diff --git a/components/firebase/login.vue b/components/firebase/login.vue index 33eb4ad82..c9423ed2a 100644 --- a/components/firebase/login.vue +++ b/components/firebase/login.vue @@ -109,7 +109,12 @@ export default { }, async signInWithGithub() { try { - const { additionalUserInfo } = await fb.signInUserWithGithub() + const { credential, additionalUserInfo } = await fb.signInUserWithGithub() + + this.$store.commit("postwoman/setProviderInfo", { + providerId: "github.com", + accessToken: credential.accessToken, + }) if (additionalUserInfo.isNewUser) { this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, { diff --git a/helpers/fb.js b/helpers/fb.js index 30c3dd7d8..d263ae062 100644 --- a/helpers/fb.js +++ b/helpers/fb.js @@ -131,7 +131,7 @@ export class FirebaseInstance { } async signInUserWithGithub() { - return await this.app.auth().signInWithPopup(this.authProviders.github()) + return await this.app.auth().signInWithPopup(this.authProviders.github().addScope("repo gist")) } async signInWithEmailAndPassword(email, password) { diff --git a/lang/en-US.json b/lang/en-US.json index d992a9378..84056defd 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -294,5 +294,8 @@ "experiments": "Experiments", "experiments_notice": "This is a collection of experiments we're working on that might turn out to be useful, fun, both, or neither. They're not final and may not be stable, so if something overly weird happens, don't panic. Just turn the dang thing off. Jokes aside, ", "use_experimental_url_bar": "Use experimental URL bar with environment highlighting", - "select_environment": "Select environment" + "select_environment": "Select environment", + "login_with_github_to": "Login with GitHub to ", + "create_secret_gist": "Create secret Gist", + "gist_created": "Gist created" } diff --git a/store/postwoman.js b/store/postwoman.js index 4f055bcb2..e21583f97 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -64,6 +64,7 @@ export const state = () => ({ editingEnvironment: {}, selectedRequest: {}, editingRequest: {}, + providerInfo: {}, }) export const mutations = { @@ -335,6 +336,10 @@ export const mutations = { } } }, + + setProviderInfo(state, value) { + state.providerInfo = value + }, } function testValue(myValue) {