Merge branch 'newstate/firebase'
This commit is contained in:
@@ -361,7 +361,6 @@ _Add-ons are developed and maintained under **[Official Hoppscotch Organization]
|
|||||||
- History
|
- History
|
||||||
- Collections
|
- Collections
|
||||||
- Environments
|
- Environments
|
||||||
- Notes
|
|
||||||
|
|
||||||
✅ **Post-Request Tests β:** Write tests associated with a request that are executed after the request response.
|
✅ **Post-Request Tests β:** Write tests associated with a request that are executed after the request response.
|
||||||
|
|
||||||
@@ -378,10 +377,6 @@ _Add-ons are developed and maintained under **[Official Hoppscotch Organization]
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
📝 **Notes** : Instantly jot down notes, tasks or whatever you feel like as they come to your mind.
|
|
||||||
|
|
||||||
_Notes are only available for signed-in users_
|
|
||||||
|
|
||||||
🌱 **Environments** : Environment variables allow you to store and reuse values in your requests and scripts.
|
🌱 **Environments** : Environment variables allow you to store and reuse values in your requests and scripts.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
<v-popover v-if="fb.currentUser === null">
|
<v-popover v-if="currentUser === null">
|
||||||
<button v-tooltip="$t('login_with')" class="icon">
|
<button v-tooltip="$t('login_with')" class="icon">
|
||||||
<i class="material-icons">login</i>
|
<i class="material-icons">login</i>
|
||||||
</button>
|
</button>
|
||||||
@@ -79,17 +79,17 @@
|
|||||||
<v-popover v-else>
|
<v-popover v-else>
|
||||||
<button
|
<button
|
||||||
v-tooltip="
|
v-tooltip="
|
||||||
(fb.currentUser.displayName ||
|
(currentUser.displayName ||
|
||||||
'<label><i>Name not found</i></label>') +
|
'<label><i>Name not found</i></label>') +
|
||||||
'<br>' +
|
'<br>' +
|
||||||
(fb.currentUser.email || '<label><i>Email not found</i></label>')
|
(currentUser.email || '<label><i>Email not found</i></label>')
|
||||||
"
|
"
|
||||||
class="icon"
|
class="icon"
|
||||||
aria-label="Account"
|
aria-label="Account"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
v-if="fb.currentUser.photoURL"
|
v-if="currentUser.photoURL"
|
||||||
:src="fb.currentUser.photoURL"
|
:src="currentUser.photoURL"
|
||||||
class="w-6 h-6 rounded-full material-icons"
|
class="w-6 h-6 rounded-full material-icons"
|
||||||
alt="Profile image"
|
alt="Profile image"
|
||||||
/>
|
/>
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import intializePwa from "~/helpers/pwa"
|
import intializePwa from "~/helpers/pwa"
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
// import { hasExtensionInstalled } from "~/helpers/strategies/ExtensionStrategy"
|
// import { hasExtensionInstalled } from "~/helpers/strategies/ExtensionStrategy"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -181,7 +181,11 @@ export default {
|
|||||||
showSupport: false,
|
showSupport: false,
|
||||||
showEmail: false,
|
showEmail: false,
|
||||||
navigatorShare: navigator.share,
|
navigatorShare: navigator.share,
|
||||||
fb,
|
}
|
||||||
|
},
|
||||||
|
subscriptions() {
|
||||||
|
return {
|
||||||
|
currentUser: currentUser$,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
|
|||||||
@@ -34,9 +34,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-tooltip.bottom="{
|
v-tooltip.bottom="{
|
||||||
content: !fb.currentUser
|
content: !currentUser
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: null,
|
: null,
|
||||||
}"
|
}"
|
||||||
@@ -44,9 +44,9 @@
|
|||||||
<button
|
<button
|
||||||
v-close-popover
|
v-close-popover
|
||||||
:disabled="
|
:disabled="
|
||||||
!fb.currentUser
|
!currentUser
|
||||||
? true
|
? true
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? true
|
? true
|
||||||
: false
|
: false
|
||||||
"
|
"
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
import * as teamUtils from "~/helpers/teams/utils"
|
import * as teamUtils from "~/helpers/teams/utils"
|
||||||
import {
|
import {
|
||||||
restCollections$,
|
restCollections$,
|
||||||
@@ -185,12 +185,12 @@ export default {
|
|||||||
mode: "import_export",
|
mode: "import_export",
|
||||||
mySelectedCollectionID: undefined,
|
mySelectedCollectionID: undefined,
|
||||||
collectionJson: "",
|
collectionJson: "",
|
||||||
fb,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscriptions() {
|
subscriptions() {
|
||||||
return {
|
return {
|
||||||
myCollections: restCollections$,
|
myCollections: restCollections$,
|
||||||
|
currentUser: currentUser$,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -208,7 +208,7 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${fb.currentUser.accessToken}`,
|
Authorization: `token ${this.currentUser.accessToken}`,
|
||||||
Accept: "application/vnd.github.v3+json",
|
Accept: "application/vnd.github.v3+json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-tooltip.bottom="{
|
v-tooltip.bottom="{
|
||||||
content: !fb.currentUser
|
content: !currentUser
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: null,
|
: null,
|
||||||
}"
|
}"
|
||||||
@@ -31,9 +31,9 @@
|
|||||||
<button
|
<button
|
||||||
v-close-popover
|
v-close-popover
|
||||||
:disabled="
|
:disabled="
|
||||||
!fb.currentUser
|
!currentUser
|
||||||
? true
|
? true
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? true
|
? true
|
||||||
: false
|
: false
|
||||||
"
|
"
|
||||||
@@ -100,7 +100,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
import {
|
import {
|
||||||
graphqlCollections$,
|
graphqlCollections$,
|
||||||
setGraphqlCollections,
|
setGraphqlCollections,
|
||||||
@@ -111,14 +111,10 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
fb,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
subscriptions() {
|
subscriptions() {
|
||||||
return {
|
return {
|
||||||
collections: graphqlCollections$,
|
collections: graphqlCollections$,
|
||||||
|
currentUser: currentUser$,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -140,7 +136,7 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${fb.currentUser.accessToken}`,
|
Authorization: `token ${this.currentUser.accessToken}`,
|
||||||
Accept: "application/vnd.github.v3+json",
|
Accept: "application/vnd.github.v3+json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import gql from "graphql-tag"
|
import gql from "graphql-tag"
|
||||||
import cloneDeep from "lodash/cloneDeep"
|
import cloneDeep from "lodash/cloneDeep"
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
import TeamCollectionAdapter from "~/helpers/teams/TeamCollectionAdapter"
|
import TeamCollectionAdapter from "~/helpers/teams/TeamCollectionAdapter"
|
||||||
import * as teamUtils from "~/helpers/teams/utils"
|
import * as teamUtils from "~/helpers/teams/utils"
|
||||||
import {
|
import {
|
||||||
@@ -184,11 +184,12 @@ export default {
|
|||||||
subscriptions() {
|
subscriptions() {
|
||||||
return {
|
return {
|
||||||
collections: restCollections$,
|
collections: restCollections$,
|
||||||
|
currentUser: currentUser$,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
showTeamCollections() {
|
showTeamCollections() {
|
||||||
if (fb.currentUser == null) {
|
if (this.currentUser == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-tooltip.bottom="{
|
v-tooltip.bottom="{
|
||||||
content: !fb.currentUser
|
content: !currentUser
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: null,
|
: null,
|
||||||
}"
|
}"
|
||||||
@@ -33,9 +33,9 @@
|
|||||||
<button
|
<button
|
||||||
v-close-popover
|
v-close-popover
|
||||||
:disabled="
|
:disabled="
|
||||||
!fb.currentUser
|
!currentUser
|
||||||
? true
|
? true
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? true
|
? true
|
||||||
: false
|
: false
|
||||||
"
|
"
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
import {
|
import {
|
||||||
environments$,
|
environments$,
|
||||||
replaceEnvironments,
|
replaceEnvironments,
|
||||||
@@ -113,14 +113,10 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
fb,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
subscriptions() {
|
subscriptions() {
|
||||||
return {
|
return {
|
||||||
environments: environments$,
|
environments: environments$,
|
||||||
|
currentUser: currentUser$,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -142,7 +138,7 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${fb.currentUser.accessToken}`,
|
Authorization: `token ${this.currentUser.accessToken}`,
|
||||||
Accept: "application/vnd.github.v3+json",
|
Accept: "application/vnd.github.v3+json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$, signInWithEmail } from "~/helpers/fb/auth"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -77,7 +77,6 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
fb,
|
|
||||||
form: {
|
form: {
|
||||||
email: "",
|
email: "",
|
||||||
},
|
},
|
||||||
@@ -88,7 +87,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$subscribeTo(fb.currentUser$, (user) => {
|
this.$subscribeTo(currentUser$, (user) => {
|
||||||
if (user) this.hideModal()
|
if (user) this.hideModal()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -99,8 +98,7 @@ export default {
|
|||||||
url: `${process.env.BASE_URL}/enter`,
|
url: `${process.env.BASE_URL}/enter`,
|
||||||
handleCodeInApp: true,
|
handleCodeInApp: true,
|
||||||
}
|
}
|
||||||
await fb
|
await signInWithEmail(this.form.email, actionCodeSettings)
|
||||||
.signInWithEmail(this.form.email, actionCodeSettings)
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.mode = "email"
|
this.mode = "email"
|
||||||
window.localStorage.setItem("emailForSignIn", this.form.email)
|
window.localStorage.setItem("emailForSignIn", this.form.email)
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div
|
|
||||||
v-if="fb.currentFeeds.length !== 0"
|
|
||||||
class="divide-y virtual-list divide-dashed divide-divider"
|
|
||||||
>
|
|
||||||
<ul v-for="feed in fb.currentFeeds" :key="feed.id" class="flex-col">
|
|
||||||
<div data-test="list-item" class="show-on-large-screen">
|
|
||||||
<li class="info">
|
|
||||||
<label data-test="list-label" class="break-all">
|
|
||||||
{{ feed.label || $t("no_label") }}
|
|
||||||
</label>
|
|
||||||
</li>
|
|
||||||
<button class="icon" @click="deleteFeed(feed)">
|
|
||||||
<i class="material-icons">delete</i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="show-on-large-screen">
|
|
||||||
<li data-test="list-message" class="info clamb-3">
|
|
||||||
<label class="break-all">{{ feed.message || $t("empty") }}</label>
|
|
||||||
</li>
|
|
||||||
</div>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<ul v-else class="flex-col">
|
|
||||||
<li>
|
|
||||||
<p class="info">{{ $t("empty") }}</p>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
fb,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async deleteFeed({ id }) {
|
|
||||||
await fb.deleteFeed(id)
|
|
||||||
this.$toast.error(this.$t("deleted"), {
|
|
||||||
icon: "delete",
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.virtual-list {
|
|
||||||
max-height: calc(100vh - 270px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.clamb-3 {
|
|
||||||
display: -webkit-box;
|
|
||||||
-webkit-line-clamp: 3;
|
|
||||||
-webkit-box-orient: vertical;
|
|
||||||
@apply overflow-hidden;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="flex-col">
|
|
||||||
<div class="show-on-large-screen">
|
|
||||||
<input
|
|
||||||
v-model="message"
|
|
||||||
:aria-label="$t('label')"
|
|
||||||
type="text"
|
|
||||||
autofocus
|
|
||||||
:placeholder="$t('paste_a_note')"
|
|
||||||
class="rounded-t-lg"
|
|
||||||
@keyup.enter="formPost"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="border-b show-on-large-screen border-divider">
|
|
||||||
<input
|
|
||||||
v-model="label"
|
|
||||||
:aria-label="$t('label')"
|
|
||||||
type="text"
|
|
||||||
autofocus
|
|
||||||
:placeholder="$t('label')"
|
|
||||||
@keyup.enter="formPost"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="icon"
|
|
||||||
:disabled="!(message || label)"
|
|
||||||
value="Save"
|
|
||||||
@click="formPost"
|
|
||||||
>
|
|
||||||
<i class="material-icons">add</i>
|
|
||||||
<span>Add</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
message: null,
|
|
||||||
label: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
formPost() {
|
|
||||||
if (!(this.message || this.label)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fb.writeFeeds(this.message, this.label)
|
|
||||||
this.message = null
|
|
||||||
this.label = null
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -40,14 +40,16 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fb } from "~/helpers/fb"
|
import { applySetting } from "~/newstore/settings"
|
||||||
|
import {
|
||||||
|
signInUserWithGoogle,
|
||||||
|
getSignInMethodsForEmail,
|
||||||
|
signInWithEmailAndPassword,
|
||||||
|
signInUserWithGithub,
|
||||||
|
setProviderInfo,
|
||||||
|
} from "~/helpers/fb/auth"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
fb,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
showLoginSuccess() {
|
showLoginSuccess() {
|
||||||
this.$toast.info(this.$t("login_success"), {
|
this.$toast.info(this.$t("login_success"), {
|
||||||
@@ -56,7 +58,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async signInWithGoogle() {
|
async signInWithGoogle() {
|
||||||
try {
|
try {
|
||||||
const { additionalUserInfo } = await fb.signInUserWithGoogle()
|
const { additionalUserInfo } = await signInUserWithGoogle()
|
||||||
|
|
||||||
if (additionalUserInfo.isNewUser) {
|
if (additionalUserInfo.isNewUser) {
|
||||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||||
@@ -66,10 +68,9 @@ export default {
|
|||||||
action: {
|
action: {
|
||||||
text: this.$t("yes"),
|
text: this.$t("yes"),
|
||||||
onClick: (_, toastObject) => {
|
onClick: (_, toastObject) => {
|
||||||
fb.writeSettings("syncHistory", true)
|
applySetting("syncHistory", true)
|
||||||
fb.writeSettings("syncCollections", true)
|
applySetting("syncCollections", true)
|
||||||
fb.writeSettings("syncEnvironments", true)
|
applySetting("syncEnvironments", true)
|
||||||
this.$router.push({ path: "/settings" })
|
|
||||||
toastObject.remove()
|
toastObject.remove()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -88,7 +89,7 @@ export default {
|
|||||||
// The provider account's email address.
|
// The provider account's email address.
|
||||||
const email = err.email
|
const email = err.email
|
||||||
// Get sign-in methods for this email.
|
// Get sign-in methods for this email.
|
||||||
const methods = await fb.getSignInMethodsForEmail(email)
|
const methods = await getSignInMethodsForEmail(email)
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
// If the user has several sign-in methods,
|
// If the user has several sign-in methods,
|
||||||
@@ -98,7 +99,7 @@ export default {
|
|||||||
// In real scenario, you should handle this asynchronously.
|
// In real scenario, you should handle this asynchronously.
|
||||||
const password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
const password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||||
|
|
||||||
const user = await fb.signInWithEmailAndPassword(email, password)
|
const user = await signInWithEmailAndPassword(email, password)
|
||||||
await user.linkWithCredential(pendingCred)
|
await user.linkWithCredential(pendingCred)
|
||||||
|
|
||||||
this.showLoginSuccess()
|
this.showLoginSuccess()
|
||||||
@@ -113,7 +114,7 @@ export default {
|
|||||||
action: {
|
action: {
|
||||||
text: this.$t("yes"),
|
text: this.$t("yes"),
|
||||||
onClick: async (_, toastObject) => {
|
onClick: async (_, toastObject) => {
|
||||||
const { user } = await fb.signInWithGithub()
|
const { user } = await signInWithGithub()
|
||||||
await user.linkAndRetrieveDataWithCredential(pendingCred)
|
await user.linkAndRetrieveDataWithCredential(pendingCred)
|
||||||
|
|
||||||
this.showLoginSuccess()
|
this.showLoginSuccess()
|
||||||
@@ -127,10 +128,9 @@ export default {
|
|||||||
},
|
},
|
||||||
async signInWithGithub() {
|
async signInWithGithub() {
|
||||||
try {
|
try {
|
||||||
const { credential, additionalUserInfo } =
|
const { credential, additionalUserInfo } = await signInUserWithGithub()
|
||||||
await fb.signInUserWithGithub()
|
|
||||||
|
|
||||||
fb.setProviderInfo(credential.providerId, credential.accessToken)
|
setProviderInfo(credential.providerId, credential.accessToken)
|
||||||
|
|
||||||
if (additionalUserInfo.isNewUser) {
|
if (additionalUserInfo.isNewUser) {
|
||||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||||
@@ -140,10 +140,9 @@ export default {
|
|||||||
action: {
|
action: {
|
||||||
text: this.$t("yes"),
|
text: this.$t("yes"),
|
||||||
onClick: (_, toastObject) => {
|
onClick: (_, toastObject) => {
|
||||||
fb.writeSettings("syncHistory", true)
|
applySetting("syncHistory", true)
|
||||||
fb.writeSettings("syncCollections", true)
|
applySetting("syncCollections", true)
|
||||||
fb.writeSettings("syncEnvironments", true)
|
applySetting("syncEnvironments", true)
|
||||||
this.$router.push({ path: "/settings" })
|
|
||||||
toastObject.remove()
|
toastObject.remove()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -162,7 +161,7 @@ export default {
|
|||||||
// The provider account's email address.
|
// The provider account's email address.
|
||||||
const email = err.email
|
const email = err.email
|
||||||
// Get sign-in methods for this email.
|
// Get sign-in methods for this email.
|
||||||
const methods = await fb.getSignInMethodsForEmail(email)
|
const methods = await getSignInMethodsForEmail(email)
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
// If the user has several sign-in methods,
|
// If the user has several sign-in methods,
|
||||||
@@ -172,7 +171,7 @@ export default {
|
|||||||
// In real scenario, you should handle this asynchronously.
|
// In real scenario, you should handle this asynchronously.
|
||||||
const password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
const password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||||
|
|
||||||
const user = await fb.signInWithEmailAndPassword(email, password)
|
const user = await signInWithEmailAndPassword(email, password)
|
||||||
await user.linkWithCredential(pendingCred)
|
await user.linkWithCredential(pendingCred)
|
||||||
|
|
||||||
this.showLoginSuccess()
|
this.showLoginSuccess()
|
||||||
@@ -187,7 +186,8 @@ export default {
|
|||||||
action: {
|
action: {
|
||||||
text: this.$t("yes"),
|
text: this.$t("yes"),
|
||||||
onClick: async (_, toastObject) => {
|
onClick: async (_, toastObject) => {
|
||||||
const { user } = await fb.signInUserWithGoogle()
|
const { user } = await signInUserWithGoogle()
|
||||||
|
// TODO: handle deprecation
|
||||||
await user.linkAndRetrieveDataWithCredential(pendingCred)
|
await user.linkAndRetrieveDataWithCredential(pendingCred)
|
||||||
|
|
||||||
this.showLoginSuccess()
|
this.showLoginSuccess()
|
||||||
|
|||||||
@@ -7,21 +7,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { fb } from "~/helpers/fb"
|
import Vue from "vue"
|
||||||
|
import { signOutUser } from "~/helpers/fb/auth"
|
||||||
|
|
||||||
export default {
|
export default Vue.extend({
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
fb,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
async logout() {
|
async logout() {
|
||||||
try {
|
try {
|
||||||
await fb.signOutUser()
|
await signOutUser()
|
||||||
|
|
||||||
this.$toast.info(this.$t("logged_out"), {
|
this.$toast.info(this.$t("logged_out").toString(), {
|
||||||
icon: "vpn_key",
|
icon: "vpn_key",
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -31,5 +27,5 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
import { shallowMount } from "@vue/test-utils"
|
|
||||||
import feeds from "../Feeds"
|
|
||||||
|
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
|
|
||||||
jest.mock("~/helpers/fb", () => ({
|
|
||||||
__esModule: true,
|
|
||||||
|
|
||||||
fb: {
|
|
||||||
currentFeeds: [
|
|
||||||
{
|
|
||||||
id: "test1",
|
|
||||||
label: "First",
|
|
||||||
message: "First Message",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "test2",
|
|
||||||
label: "Second",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "test3",
|
|
||||||
message: "Third Message",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "test4",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
deleteFeed: jest.fn(() => Promise.resolve()),
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
const factory = () =>
|
|
||||||
shallowMount(feeds, {
|
|
||||||
mocks: {
|
|
||||||
$t: (text) => text,
|
|
||||||
$toast: {
|
|
||||||
error: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fb.deleteFeed.mockClear()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("feeds", () => {
|
|
||||||
test("mounts properly when proper components are given", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(wrapper).toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("renders all the current feeds", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(wrapper.findAll("div[data-test='list-item']").wrappers).toHaveLength(
|
|
||||||
4
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("feeds with no label displays the 'no_label' message", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(
|
|
||||||
wrapper
|
|
||||||
.findAll("label[data-test='list-label']")
|
|
||||||
.wrappers.map((e) => e.text())
|
|
||||||
.filter((text) => text === "no_label")
|
|
||||||
).toHaveLength(2)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("feeds with no message displays the 'empty' message", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(
|
|
||||||
wrapper
|
|
||||||
.findAll("li[data-test='list-message']")
|
|
||||||
.wrappers.map((e) => e.text())
|
|
||||||
.filter((text) => text === "empty")
|
|
||||||
).toHaveLength(2)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("labels in the list are proper", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(
|
|
||||||
wrapper
|
|
||||||
.findAll("label[data-test='list-label']")
|
|
||||||
.wrappers.map((e) => e.text())
|
|
||||||
).toEqual(["First", "Second", "no_label", "no_label"])
|
|
||||||
})
|
|
||||||
|
|
||||||
test("messages in the list are proper", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(
|
|
||||||
wrapper
|
|
||||||
.findAll("li[data-test='list-message']")
|
|
||||||
.wrappers.map((e) => e.text())
|
|
||||||
).toEqual(["First Message", "empty", "Third Message", "empty"])
|
|
||||||
})
|
|
||||||
|
|
||||||
test("clicking on the delete button deletes the feed", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const deleteButton = wrapper.find("button")
|
|
||||||
|
|
||||||
await deleteButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.deleteFeed).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("correct feed is passed to from the list for deletion", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const deleteButton = wrapper.find("button")
|
|
||||||
|
|
||||||
await deleteButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.deleteFeed).toHaveBeenCalledWith("test1")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("renders the 'empty' label if no elements in the current feeds", () => {
|
|
||||||
jest.spyOn(fb, "currentFeeds", "get").mockReturnValueOnce([])
|
|
||||||
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(wrapper.findAll("li").wrappers).toHaveLength(1)
|
|
||||||
|
|
||||||
expect(wrapper.find("li").text()).toEqual("empty")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
import { shallowMount } from "@vue/test-utils"
|
|
||||||
import inputform from "../Inputform"
|
|
||||||
|
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
|
|
||||||
jest.mock("~/helpers/fb", () => ({
|
|
||||||
__esModule: true,
|
|
||||||
|
|
||||||
fb: {
|
|
||||||
writeFeeds: jest.fn(() => Promise.resolve()),
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
const factory = () =>
|
|
||||||
shallowMount(inputform, {
|
|
||||||
mocks: {
|
|
||||||
$t: (text) => text,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fb.writeFeeds.mockClear()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("inputform", () => {
|
|
||||||
test("mounts properly", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(wrapper).toBeTruthy()
|
|
||||||
})
|
|
||||||
test("calls writeFeeds when submitted properly", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const addButton = wrapper.find("button")
|
|
||||||
const [messageInput, labelInput] = wrapper.findAll("input").wrappers
|
|
||||||
|
|
||||||
await messageInput.setValue("test message")
|
|
||||||
await labelInput.setValue("test label")
|
|
||||||
|
|
||||||
await addButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.writeFeeds).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
|
||||||
test("doesn't call writeFeeds when submitted without a data", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const addButton = wrapper.find("button")
|
|
||||||
|
|
||||||
await addButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.writeFeeds).not.toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
test("doesn't call writeFeeds when message or label is null", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const addButton = wrapper.find("button")
|
|
||||||
const [messageInput, labelInput] = wrapper.findAll("input").wrappers
|
|
||||||
|
|
||||||
await messageInput.setValue(null)
|
|
||||||
await labelInput.setValue(null)
|
|
||||||
|
|
||||||
await addButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.writeFeeds).not.toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
test("doesn't call writeFeeds when message or label is empty", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const addButton = wrapper.find("button")
|
|
||||||
const [messageInput, labelInput] = wrapper.findAll("input").wrappers
|
|
||||||
|
|
||||||
await messageInput.setValue("")
|
|
||||||
await labelInput.setValue("")
|
|
||||||
|
|
||||||
await addButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.writeFeeds).not.toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
test("calls writeFeeds with correct values", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const addButton = wrapper.find("button")
|
|
||||||
const [messageInput, labelInput] = wrapper.findAll("input").wrappers
|
|
||||||
|
|
||||||
await messageInput.setValue("test message")
|
|
||||||
await labelInput.setValue("test label")
|
|
||||||
|
|
||||||
await addButton.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.writeFeeds).toHaveBeenCalledWith("test message", "test label")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import { shallowMount, createLocalVue } from "@vue/test-utils"
|
|
||||||
import logout from "../Logout"
|
|
||||||
|
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
|
|
||||||
jest.mock("~/helpers/fb", () => ({
|
|
||||||
__esModule: true,
|
|
||||||
|
|
||||||
fb: {
|
|
||||||
signOutUser: jest.fn(() => Promise.resolve()),
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
const $toast = {
|
|
||||||
info: jest.fn(),
|
|
||||||
show: jest.fn(),
|
|
||||||
}
|
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
|
||||||
|
|
||||||
localVue.directive("close-popover", {})
|
|
||||||
|
|
||||||
const factory = () =>
|
|
||||||
shallowMount(logout, {
|
|
||||||
mocks: {
|
|
||||||
$t: (text) => text,
|
|
||||||
$toast,
|
|
||||||
},
|
|
||||||
localVue,
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fb.signOutUser.mockClear()
|
|
||||||
$toast.info.mockClear()
|
|
||||||
$toast.show.mockClear()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("logout", () => {
|
|
||||||
test("mounts properly", () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
expect(wrapper).toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("clicking the logout button fires the logout firebase function", async () => {
|
|
||||||
const wrapper = factory()
|
|
||||||
|
|
||||||
const button = wrapper.find("button")
|
|
||||||
|
|
||||||
await button.trigger("click")
|
|
||||||
|
|
||||||
expect(fb.signOutUser).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("failed signout request fires a error toast", async () => {
|
|
||||||
fb.signOutUser.mockImplementationOnce(() =>
|
|
||||||
Promise.reject(new Error("test reject"))
|
|
||||||
)
|
|
||||||
|
|
||||||
const wrapper = factory()
|
|
||||||
const button = wrapper.find("button")
|
|
||||||
await button.trigger("click")
|
|
||||||
|
|
||||||
expect($toast.show).toHaveBeenCalledTimes(1)
|
|
||||||
expect($toast.show).toHaveBeenCalledWith("test reject", expect.anything())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<template>
|
|
||||||
<AppSection ref="sync" :label="$t('notes')">
|
|
||||||
<div v-if="fb.currentUser">
|
|
||||||
<FirebaseInputform />
|
|
||||||
<FirebaseFeeds />
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<p class="info">{{ $t("login_first") }}</p>
|
|
||||||
<FirebaseLogin @show-email="showEmail = true" />
|
|
||||||
</div>
|
|
||||||
<FirebaseEmail :show="showEmail" @hide-modal="showEmail = false" />
|
|
||||||
</AppSection>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
fb,
|
|
||||||
showEmail: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<AppSection ref="teams" :label="$t('teams')">
|
<AppSection ref="teams" :label="$t('teams')">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label>{{ $t("teams") }}</label>
|
<label>{{ $t("teams") }}</label>
|
||||||
<div v-if="fb.currentUser"></div>
|
<div v-if="currentUser"></div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<label>{{ $t("login_with") }}</label>
|
<label>{{ $t("login_with") }}</label>
|
||||||
<p>
|
<p>
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import gql from "graphql-tag"
|
import gql from "graphql-tag"
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -61,10 +61,14 @@ export default {
|
|||||||
editingteamID: "",
|
editingteamID: "",
|
||||||
me: {},
|
me: {},
|
||||||
myTeams: [],
|
myTeams: [],
|
||||||
fb,
|
|
||||||
showEmail: false,
|
showEmail: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
subscriptions() {
|
||||||
|
return {
|
||||||
|
currentUser: currentUser$,
|
||||||
|
}
|
||||||
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
me: {
|
me: {
|
||||||
query: gql`
|
query: gql`
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import {
|
|||||||
import { WebSocketLink } from "@apollo/client/link/ws"
|
import { WebSocketLink } from "@apollo/client/link/ws"
|
||||||
import { setContext } from "@apollo/client/link/context"
|
import { setContext } from "@apollo/client/link/context"
|
||||||
import { getMainDefinition } from "@apollo/client/utilities"
|
import { getMainDefinition } from "@apollo/client/utilities"
|
||||||
import { fb } from "./fb"
|
import { authIdToken$ } from "./fb/auth"
|
||||||
|
|
||||||
let authToken: String | null = null
|
let authToken: String | null = null
|
||||||
|
|
||||||
export function registerApolloAuthUpdate() {
|
export function registerApolloAuthUpdate() {
|
||||||
fb.idToken$.subscribe((token: String | null) => {
|
authIdToken$.subscribe((token) => {
|
||||||
authToken = token
|
authToken = token
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
572
helpers/fb.js
572
helpers/fb.js
@@ -1,572 +0,0 @@
|
|||||||
import firebase from "firebase/app"
|
|
||||||
import "firebase/firestore"
|
|
||||||
import "firebase/auth"
|
|
||||||
import { ReplaySubject } from "rxjs"
|
|
||||||
import { applySettingFB, settingsStore } from "~/newstore/settings"
|
|
||||||
import {
|
|
||||||
restHistoryStore,
|
|
||||||
setRESTHistoryEntries,
|
|
||||||
graphqlHistoryStore,
|
|
||||||
setGraphqlHistoryEntries,
|
|
||||||
HISTORY_LIMIT,
|
|
||||||
} from "~/newstore/history"
|
|
||||||
import {
|
|
||||||
restCollectionStore,
|
|
||||||
setRESTCollections,
|
|
||||||
graphqlCollectionStore,
|
|
||||||
setGraphqlCollections,
|
|
||||||
} from "~/newstore/collections"
|
|
||||||
import { environments$, replaceEnvironments } from "~/newstore/environments"
|
|
||||||
|
|
||||||
// Initialize Firebase, copied from cloud console
|
|
||||||
const firebaseConfig = {
|
|
||||||
apiKey: process.env.API_KEY,
|
|
||||||
authDomain: process.env.AUTH_DOMAIN,
|
|
||||||
databaseURL: process.env.DATABASE_URL,
|
|
||||||
projectId: process.env.PROJECT_ID,
|
|
||||||
storageBucket: process.env.STORAGE_BUCKET,
|
|
||||||
messagingSenderId: process.env.MESSAGING_SENDER_ID,
|
|
||||||
appId: process.env.APP_ID,
|
|
||||||
measurementId: process.env.MEASUREMENT_ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const authProviders = {
|
|
||||||
google: () => new firebase.auth.GoogleAuthProvider(),
|
|
||||||
github: () => new firebase.auth.GithubAuthProvider(),
|
|
||||||
}
|
|
||||||
|
|
||||||
export class FirebaseInstance {
|
|
||||||
constructor(fbapp, authProviders) {
|
|
||||||
this.app = fbapp
|
|
||||||
this.authProviders = authProviders
|
|
||||||
|
|
||||||
this.usersCollection = this.app.firestore().collection("users")
|
|
||||||
|
|
||||||
this.currentUser = null
|
|
||||||
this.idToken = null
|
|
||||||
this.currentFeeds = []
|
|
||||||
this.currentSettings = []
|
|
||||||
|
|
||||||
this.currentUser$ = new ReplaySubject(1)
|
|
||||||
this.idToken$ = new ReplaySubject(1)
|
|
||||||
|
|
||||||
let loadedSettings = false
|
|
||||||
let loadedRESTHistory = false
|
|
||||||
let loadedGraphqlHistory = false
|
|
||||||
let loadedRESTCollections = false
|
|
||||||
let loadedGraphqlCollections = false
|
|
||||||
let loadedEnvironments = false
|
|
||||||
|
|
||||||
graphqlCollectionStore.subject$.subscribe(({ state }) => {
|
|
||||||
if (
|
|
||||||
loadedGraphqlCollections &&
|
|
||||||
this.currentUser &&
|
|
||||||
settingsStore.value.syncCollections
|
|
||||||
) {
|
|
||||||
this.writeCollections(state, "collectionsGraphql")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
restCollectionStore.subject$.subscribe(({ state }) => {
|
|
||||||
if (
|
|
||||||
loadedRESTCollections &&
|
|
||||||
this.currentUser &&
|
|
||||||
settingsStore.value.syncCollections
|
|
||||||
) {
|
|
||||||
this.writeCollections(state, "collections")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
restHistoryStore.dispatches$.subscribe((dispatch) => {
|
|
||||||
if (
|
|
||||||
loadedRESTHistory &&
|
|
||||||
this.currentUser &&
|
|
||||||
settingsStore.value.syncHistory
|
|
||||||
) {
|
|
||||||
if (dispatch.dispatcher === "addEntry") {
|
|
||||||
this.writeHistory(dispatch.payload.entry)
|
|
||||||
} else if (dispatch.dispatcher === "deleteEntry") {
|
|
||||||
this.deleteHistory(dispatch.payload.entry)
|
|
||||||
} else if (dispatch.dispatcher === "clearHistory") {
|
|
||||||
this.clearHistory()
|
|
||||||
} else if (dispatch.dispatcher === "toggleStar") {
|
|
||||||
this.toggleStar(dispatch.payload.entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
graphqlHistoryStore.dispatches$.subscribe((dispatch) => {
|
|
||||||
if (
|
|
||||||
loadedGraphqlHistory &&
|
|
||||||
this.currentUser &&
|
|
||||||
settingsStore.value.syncHistory
|
|
||||||
) {
|
|
||||||
if (dispatch.dispatcher === "addEntry") {
|
|
||||||
this.writeGraphqlHistory(dispatch.payload.entry)
|
|
||||||
} else if (dispatch.dispatcher === "deleteEntry") {
|
|
||||||
this.deleteGraphqlHistory(dispatch.payload.entry)
|
|
||||||
} else if (dispatch.dispatcher === "clearHistory") {
|
|
||||||
this.clearGraphqlHistory()
|
|
||||||
} else if (dispatch.dispatcher === "toggleStar") {
|
|
||||||
this.toggleGraphqlHistoryStar(dispatch.payload.entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
settingsStore.dispatches$.subscribe((dispatch) => {
|
|
||||||
if (this.currentUser && loadedSettings) {
|
|
||||||
if (dispatch.dispatcher === "bulkApplySettings") {
|
|
||||||
Object.keys(dispatch.payload).forEach((key) => {
|
|
||||||
this.writeSettings(key, dispatch.payload[key])
|
|
||||||
})
|
|
||||||
} else if (dispatch.dispatcher !== "applySettingFB") {
|
|
||||||
this.writeSettings(
|
|
||||||
dispatch.payload.settingKey,
|
|
||||||
settingsStore.value[dispatch.payload.settingKey]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
environments$.subscribe((envs) => {
|
|
||||||
if (this.currentUser && loadedEnvironments) {
|
|
||||||
this.writeEnvironments(envs)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.app.auth().onIdTokenChanged((user) => {
|
|
||||||
if (user) {
|
|
||||||
user.getIdToken().then((token) => {
|
|
||||||
this.idToken = token
|
|
||||||
this.idToken$.next(token)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.idToken = null
|
|
||||||
this.idToken$.next(null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.app.auth().onAuthStateChanged((user) => {
|
|
||||||
this.currentUser$.next(user)
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
this.currentUser = user
|
|
||||||
|
|
||||||
this.currentUser.providerData.forEach((profile) => {
|
|
||||||
const us = {
|
|
||||||
updatedOn: new Date(),
|
|
||||||
provider: profile.providerId,
|
|
||||||
name: profile.displayName,
|
|
||||||
email: profile.email,
|
|
||||||
photoUrl: profile.photoURL,
|
|
||||||
uid: profile.uid,
|
|
||||||
}
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.set(us, { merge: true })
|
|
||||||
.catch((e) => console.error("error updating", us, e))
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection.doc(this.currentUser.uid).onSnapshot((doc) => {
|
|
||||||
this.currentUser.provider = doc.data().provider
|
|
||||||
this.currentUser.accessToken = doc.data().accessToken
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("feeds")
|
|
||||||
.orderBy("createdOn", "desc")
|
|
||||||
.onSnapshot((feedsRef) => {
|
|
||||||
const feeds = []
|
|
||||||
feedsRef.forEach((doc) => {
|
|
||||||
const feed = doc.data()
|
|
||||||
feed.id = doc.id
|
|
||||||
feeds.push(feed)
|
|
||||||
})
|
|
||||||
this.currentFeeds = feeds
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("settings")
|
|
||||||
.onSnapshot((settingsRef) => {
|
|
||||||
const settings = []
|
|
||||||
settingsRef.forEach((doc) => {
|
|
||||||
const setting = doc.data()
|
|
||||||
setting.id = doc.id
|
|
||||||
settings.push(setting)
|
|
||||||
})
|
|
||||||
this.currentSettings = settings
|
|
||||||
|
|
||||||
settings.forEach((e) => {
|
|
||||||
if (e && e.name && e.value != null) {
|
|
||||||
applySettingFB(e.name, e.value)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
loadedSettings = true
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("history")
|
|
||||||
.orderBy("updatedOn", "desc")
|
|
||||||
.limit(HISTORY_LIMIT)
|
|
||||||
.onSnapshot((historyRef) => {
|
|
||||||
const history = []
|
|
||||||
|
|
||||||
historyRef.forEach((doc) => {
|
|
||||||
const entry = doc.data()
|
|
||||||
entry.id = doc.id
|
|
||||||
history.push(entry)
|
|
||||||
})
|
|
||||||
|
|
||||||
setRESTHistoryEntries(history)
|
|
||||||
|
|
||||||
loadedRESTHistory = true
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("graphqlHistory")
|
|
||||||
.orderBy("updatedOn", "desc")
|
|
||||||
.limit(HISTORY_LIMIT)
|
|
||||||
.onSnapshot((historyRef) => {
|
|
||||||
const history = []
|
|
||||||
|
|
||||||
historyRef.forEach((doc) => {
|
|
||||||
const entry = doc.data()
|
|
||||||
entry.id = doc.id
|
|
||||||
history.push(entry)
|
|
||||||
})
|
|
||||||
|
|
||||||
setGraphqlHistoryEntries(history)
|
|
||||||
|
|
||||||
loadedGraphqlHistory = true
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("collections")
|
|
||||||
.onSnapshot((collectionsRef) => {
|
|
||||||
const collections = []
|
|
||||||
collectionsRef.forEach((doc) => {
|
|
||||||
const collection = doc.data()
|
|
||||||
collection.id = doc.id
|
|
||||||
collections.push(collection)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Prevent infinite ping-pong of updates
|
|
||||||
loadedRESTCollections = false
|
|
||||||
|
|
||||||
// TODO: Wth is with collections[0]
|
|
||||||
if (collections.length > 0) {
|
|
||||||
setRESTCollections(collections[0].collection)
|
|
||||||
}
|
|
||||||
|
|
||||||
loadedRESTCollections = true
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("collectionsGraphql")
|
|
||||||
.onSnapshot((collectionsRef) => {
|
|
||||||
const collections = []
|
|
||||||
collectionsRef.forEach((doc) => {
|
|
||||||
const collection = doc.data()
|
|
||||||
collection.id = doc.id
|
|
||||||
collections.push(collection)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Prevent infinite ping-pong of updates
|
|
||||||
loadedGraphqlCollections = false
|
|
||||||
|
|
||||||
// TODO: Wth is with collections[0]
|
|
||||||
if (collections.length > 0) {
|
|
||||||
setGraphqlCollections(collections[0].collection)
|
|
||||||
}
|
|
||||||
|
|
||||||
loadedGraphqlCollections = true
|
|
||||||
})
|
|
||||||
|
|
||||||
this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("environments")
|
|
||||||
.onSnapshot((environmentsRef) => {
|
|
||||||
const environments = []
|
|
||||||
environmentsRef.forEach((doc) => {
|
|
||||||
const environment = doc.data()
|
|
||||||
environment.id = doc.id
|
|
||||||
environments.push(environment)
|
|
||||||
})
|
|
||||||
loadedEnvironments = false
|
|
||||||
replaceEnvironments(environments[0].environment)
|
|
||||||
loadedEnvironments = true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.currentUser = null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async signInUserWithGoogle() {
|
|
||||||
return await this.app.auth().signInWithPopup(this.authProviders.google())
|
|
||||||
}
|
|
||||||
|
|
||||||
async signInUserWithGithub() {
|
|
||||||
return await this.app
|
|
||||||
.auth()
|
|
||||||
.signInWithPopup(this.authProviders.github().addScope("gist"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async signInWithEmailAndPassword(email, password) {
|
|
||||||
return await this.app.auth().signInWithEmailAndPassword(email, password)
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSignInMethodsForEmail(email) {
|
|
||||||
return await this.app.auth().fetchSignInMethodsForEmail(email)
|
|
||||||
}
|
|
||||||
|
|
||||||
async signInWithEmail(email, actionCodeSettings) {
|
|
||||||
return await this.app
|
|
||||||
.auth()
|
|
||||||
.sendSignInLinkToEmail(email, actionCodeSettings)
|
|
||||||
}
|
|
||||||
|
|
||||||
async isSignInWithEmailLink(url) {
|
|
||||||
return await this.app.auth().isSignInWithEmailLink(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
async signInWithEmailLink(email, url) {
|
|
||||||
return await this.app.auth().signInWithEmailLink(email, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
async signOutUser() {
|
|
||||||
if (!this.currentUser) throw new Error("No user has logged in")
|
|
||||||
|
|
||||||
await this.app.auth().signOut()
|
|
||||||
this.currentUser = null
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeFeeds(message, label) {
|
|
||||||
const dt = {
|
|
||||||
createdOn: new Date(),
|
|
||||||
author: this.currentUser.uid,
|
|
||||||
author_name: this.currentUser.displayName,
|
|
||||||
author_image: this.currentUser.photoURL,
|
|
||||||
message,
|
|
||||||
label,
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("feeds")
|
|
||||||
.add(dt)
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error inserting", dt, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteFeed(id) {
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("feeds")
|
|
||||||
.doc(id)
|
|
||||||
.delete()
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error deleting", id, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeSettings(setting, value) {
|
|
||||||
const st = {
|
|
||||||
updatedOn: new Date(),
|
|
||||||
author: this.currentUser.uid,
|
|
||||||
author_name: this.currentUser.displayName,
|
|
||||||
author_image: this.currentUser.photoURL,
|
|
||||||
name: setting,
|
|
||||||
value,
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("settings")
|
|
||||||
.doc(setting)
|
|
||||||
.set(st)
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error updating", st, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeHistory(entry) {
|
|
||||||
const hs = entry
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("history")
|
|
||||||
.add(hs)
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error inserting", hs, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeGraphqlHistory(entry) {
|
|
||||||
const hs = entry
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("graphqlHistory")
|
|
||||||
.add(hs)
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error inserting", hs, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteHistory(entry) {
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("history")
|
|
||||||
.doc(entry.id)
|
|
||||||
.delete()
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error deleting", entry, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteGraphqlHistory(entry) {
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("graphqlHistory")
|
|
||||||
.doc(entry.id)
|
|
||||||
.delete()
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error deleting", entry, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async clearHistory() {
|
|
||||||
const { docs } = await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("history")
|
|
||||||
.get()
|
|
||||||
|
|
||||||
await Promise.all(docs.map((e) => this.deleteHistory(e)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async clearGraphqlHistory() {
|
|
||||||
const { docs } = await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("graphqlHistory")
|
|
||||||
.get()
|
|
||||||
|
|
||||||
await Promise.all(docs.map((e) => this.deleteGraphqlHistory(e)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleStar(entry) {
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("history")
|
|
||||||
.doc(entry.id)
|
|
||||||
.update({ star: !entry.star })
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error deleting", entry, e)
|
|
||||||
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleGraphqlHistoryStar(entry) {
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("graphqlHistory")
|
|
||||||
.doc(entry.id)
|
|
||||||
.update({ star: !entry.star })
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error deleting", entry, e)
|
|
||||||
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeCollections(collection, flag) {
|
|
||||||
const cl = {
|
|
||||||
updatedOn: new Date(),
|
|
||||||
author: this.currentUser.uid,
|
|
||||||
author_name: this.currentUser.displayName,
|
|
||||||
author_image: this.currentUser.photoURL,
|
|
||||||
collection,
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection(flag)
|
|
||||||
.doc("sync")
|
|
||||||
.set(cl)
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error updating", cl, e)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async writeEnvironments(environment) {
|
|
||||||
const ev = {
|
|
||||||
updatedOn: new Date(),
|
|
||||||
author: this.currentUser.uid,
|
|
||||||
author_name: this.currentUser.displayName,
|
|
||||||
author_image: this.currentUser.photoURL,
|
|
||||||
environment,
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.collection("environments")
|
|
||||||
.doc("sync")
|
|
||||||
.set(ev)
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error updating", ev, e)
|
|
||||||
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setProviderInfo(id, token) {
|
|
||||||
const us = {
|
|
||||||
updatedOn: new Date(),
|
|
||||||
provider: id,
|
|
||||||
accessToken: token,
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await this.usersCollection
|
|
||||||
.doc(this.currentUser.uid)
|
|
||||||
.update(us)
|
|
||||||
.catch((e) => console.error("error updating", us, e))
|
|
||||||
} catch (e) {
|
|
||||||
console.error("error updating", e)
|
|
||||||
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fb = new FirebaseInstance(
|
|
||||||
firebase.initializeApp(firebaseConfig),
|
|
||||||
authProviders
|
|
||||||
)
|
|
||||||
186
helpers/fb/auth.ts
Normal file
186
helpers/fb/auth.ts
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
import firebase from "firebase"
|
||||||
|
import { BehaviorSubject } from "rxjs"
|
||||||
|
|
||||||
|
export type HoppUser = firebase.User & {
|
||||||
|
provider?: string
|
||||||
|
accessToken?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A BehaviorSubject emitting the currently logged in user (or null if not logged in)
|
||||||
|
*/
|
||||||
|
export const currentUser$ = new BehaviorSubject<HoppUser | null>(null)
|
||||||
|
/**
|
||||||
|
* A BehaviorSubject emitting the current idToken
|
||||||
|
*/
|
||||||
|
export const authIdToken$ = new BehaviorSubject<string | null>(null)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the firebase authentication related subjects
|
||||||
|
*/
|
||||||
|
export function initAuth() {
|
||||||
|
let extraSnapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
|
firebase.auth().onAuthStateChanged((user) => {
|
||||||
|
if (!user && extraSnapshotStop) {
|
||||||
|
extraSnapshotStop()
|
||||||
|
extraSnapshotStop = null
|
||||||
|
} else if (user) {
|
||||||
|
// Merge all the user info from all the authenticated providers
|
||||||
|
user.providerData.forEach((profile) => {
|
||||||
|
if (!profile) return
|
||||||
|
|
||||||
|
const us = {
|
||||||
|
updatedOn: new Date(),
|
||||||
|
provider: profile.providerId,
|
||||||
|
name: profile.displayName,
|
||||||
|
email: profile.email,
|
||||||
|
photoUrl: profile.photoURL,
|
||||||
|
uid: profile.uid,
|
||||||
|
}
|
||||||
|
|
||||||
|
firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.set(us, { merge: true })
|
||||||
|
.catch((e) => console.error("error updating", us, e))
|
||||||
|
})
|
||||||
|
|
||||||
|
extraSnapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.onSnapshot((doc) => {
|
||||||
|
const data = doc.data()
|
||||||
|
|
||||||
|
const userUpdate: HoppUser = user
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
// Write extra provider data
|
||||||
|
userUpdate.provider = data.provider
|
||||||
|
userUpdate.accessToken = data.accessToken
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
currentUser$.next(user)
|
||||||
|
})
|
||||||
|
|
||||||
|
firebase.auth().onIdTokenChanged(async (user) => {
|
||||||
|
if (user) {
|
||||||
|
authIdToken$.next(await user.getIdToken())
|
||||||
|
} else {
|
||||||
|
authIdToken$.next(null)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign user in with a popup using Google
|
||||||
|
*/
|
||||||
|
export async function signInUserWithGoogle() {
|
||||||
|
return await firebase
|
||||||
|
.auth()
|
||||||
|
.signInWithPopup(new firebase.auth.GoogleAuthProvider())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign user in with a popup using Github
|
||||||
|
*/
|
||||||
|
export async function signInUserWithGithub() {
|
||||||
|
return await firebase
|
||||||
|
.auth()
|
||||||
|
.signInWithPopup(new firebase.auth.GithubAuthProvider().addScope("gist"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign user in with email and password
|
||||||
|
*/
|
||||||
|
export async function signInWithEmailAndPassword(
|
||||||
|
email: string,
|
||||||
|
password: string
|
||||||
|
) {
|
||||||
|
return await firebase.auth().signInWithEmailAndPassword(email, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the sign in methods for a given email address
|
||||||
|
*
|
||||||
|
* @param email - Email to get the methods of
|
||||||
|
*
|
||||||
|
* @returns Promise for string array of the auth provider methods accessible
|
||||||
|
*/
|
||||||
|
export async function getSignInMethodsForEmail(email: string) {
|
||||||
|
return await firebase.auth().fetchSignInMethodsForEmail(email)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an email with the signin link to the user
|
||||||
|
*
|
||||||
|
* @param email - Email to send the email to
|
||||||
|
* @param actionCodeSettings - The settings to apply to the link
|
||||||
|
*/
|
||||||
|
export async function signInWithEmail(
|
||||||
|
email: string,
|
||||||
|
actionCodeSettings: firebase.auth.ActionCodeSettings
|
||||||
|
) {
|
||||||
|
return await firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks and returns whether the sign in link is an email link
|
||||||
|
*
|
||||||
|
* @param url - The URL to look in
|
||||||
|
*/
|
||||||
|
export function isSignInWithEmailLink(url: string) {
|
||||||
|
return firebase.auth().isSignInWithEmailLink(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an email with sign in with email link
|
||||||
|
*
|
||||||
|
* @param email - Email to log in to
|
||||||
|
* @param url - The action URL which is used to validate login
|
||||||
|
*/
|
||||||
|
export async function signInWithEmailLink(email: string, url: string) {
|
||||||
|
return await firebase.auth().signInWithEmailLink(email, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signs out the user
|
||||||
|
*/
|
||||||
|
export async function signOutUser() {
|
||||||
|
if (!currentUser$.value) throw new Error("No user has logged in")
|
||||||
|
|
||||||
|
await firebase.auth().signOut()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the provider id and relevant provider auth token
|
||||||
|
* as user metadata
|
||||||
|
*
|
||||||
|
* @param id - The provider ID
|
||||||
|
* @param token - The relevant auth token for the given provider
|
||||||
|
*/
|
||||||
|
export async function setProviderInfo(id: string, token: string) {
|
||||||
|
if (!currentUser$.value) throw new Error("No user has logged in")
|
||||||
|
|
||||||
|
const us = {
|
||||||
|
updatedOn: new Date(),
|
||||||
|
provider: id,
|
||||||
|
accessToken: token,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.update(us)
|
||||||
|
.catch((e) => console.error("error updating", us, e))
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error updating", e)
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
147
helpers/fb/collections.ts
Normal file
147
helpers/fb/collections.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import firebase from "firebase"
|
||||||
|
import { currentUser$ } from "./auth"
|
||||||
|
import {
|
||||||
|
restCollections$,
|
||||||
|
graphqlCollections$,
|
||||||
|
setRESTCollections,
|
||||||
|
setGraphqlCollections,
|
||||||
|
} from "~/newstore/collections"
|
||||||
|
import { settingsStore } from "~/newstore/settings"
|
||||||
|
|
||||||
|
type CollectionFlags = "collectionsGraphql" | "collections"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the collections are loaded. If this is set to true
|
||||||
|
* Updates to the collections store are written into firebase.
|
||||||
|
*
|
||||||
|
* If you have want to update the store and not fire the store update
|
||||||
|
* subscription, set this variable to false, do the update and then
|
||||||
|
* set it to true
|
||||||
|
*/
|
||||||
|
let loadedRESTCollections = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the collections are loaded. If this is set to true
|
||||||
|
* Updates to the collections store are written into firebase.
|
||||||
|
*
|
||||||
|
* If you have want to update the store and not fire the store update
|
||||||
|
* subscription, set this variable to false, do the update and then
|
||||||
|
* set it to true
|
||||||
|
*/
|
||||||
|
let loadedGraphqlCollections = false
|
||||||
|
|
||||||
|
export async function writeCollections(
|
||||||
|
collection: any[],
|
||||||
|
flag: CollectionFlags
|
||||||
|
) {
|
||||||
|
if (currentUser$.value === null)
|
||||||
|
throw new Error("User not logged in to write collections")
|
||||||
|
|
||||||
|
const cl = {
|
||||||
|
updatedOn: new Date(),
|
||||||
|
author: currentUser$.value.uid,
|
||||||
|
author_name: currentUser$.value.displayName,
|
||||||
|
author_image: currentUser$.value.photoURL,
|
||||||
|
collection,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection(flag)
|
||||||
|
.doc("sync")
|
||||||
|
.set(cl)
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error updating", cl, e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initCollections() {
|
||||||
|
restCollections$.subscribe((collections) => {
|
||||||
|
if (
|
||||||
|
loadedRESTCollections &&
|
||||||
|
currentUser$.value &&
|
||||||
|
settingsStore.value.syncCollections
|
||||||
|
) {
|
||||||
|
writeCollections(collections, "collections")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
graphqlCollections$.subscribe((collections) => {
|
||||||
|
if (
|
||||||
|
loadedGraphqlCollections &&
|
||||||
|
currentUser$.value &&
|
||||||
|
settingsStore.value.syncCollections
|
||||||
|
) {
|
||||||
|
writeCollections(collections, "collectionsGraphql")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let restSnapshotStop: (() => void) | null = null
|
||||||
|
let graphqlSnapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
|
currentUser$.subscribe((user) => {
|
||||||
|
if (!user) {
|
||||||
|
if (restSnapshotStop) {
|
||||||
|
restSnapshotStop()
|
||||||
|
restSnapshotStop = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graphqlSnapshotStop) {
|
||||||
|
graphqlSnapshotStop()
|
||||||
|
graphqlSnapshotStop = null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restSnapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.collection("collections")
|
||||||
|
.onSnapshot((collectionsRef) => {
|
||||||
|
const collections: any[] = []
|
||||||
|
collectionsRef.forEach((doc) => {
|
||||||
|
const collection = doc.data()
|
||||||
|
collection.id = doc.id
|
||||||
|
collections.push(collection)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Prevent infinite ping-pong of updates
|
||||||
|
loadedRESTCollections = false
|
||||||
|
|
||||||
|
// TODO: Wth is with collections[0]
|
||||||
|
if (collections.length > 0) {
|
||||||
|
setRESTCollections(collections[0].collection)
|
||||||
|
}
|
||||||
|
|
||||||
|
loadedRESTCollections = true
|
||||||
|
})
|
||||||
|
|
||||||
|
graphqlSnapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.collection("collectionsGraphql")
|
||||||
|
.onSnapshot((collectionsRef) => {
|
||||||
|
const collections: any[] = []
|
||||||
|
collectionsRef.forEach((doc) => {
|
||||||
|
const collection = doc.data()
|
||||||
|
collection.id = doc.id
|
||||||
|
collections.push(collection)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Prevent infinite ping-pong of updates
|
||||||
|
loadedGraphqlCollections = false
|
||||||
|
|
||||||
|
// TODO: Wth is with collections[0]
|
||||||
|
if (collections.length > 0) {
|
||||||
|
setGraphqlCollections(collections[0].collection)
|
||||||
|
}
|
||||||
|
|
||||||
|
loadedGraphqlCollections = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
84
helpers/fb/environments.ts
Normal file
84
helpers/fb/environments.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import firebase from "firebase"
|
||||||
|
import { currentUser$ } from "./auth"
|
||||||
|
import {
|
||||||
|
Environment,
|
||||||
|
environments$,
|
||||||
|
replaceEnvironments,
|
||||||
|
} from "~/newstore/environments"
|
||||||
|
import { settingsStore } from "~/newstore/settings"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used locally to prevent infinite loop when environment sync update
|
||||||
|
* is applied to the store which then fires the store sync listener.
|
||||||
|
* When you want to update environments and not want to fire the update listener,
|
||||||
|
* set this to true and then set it back to false once it is done
|
||||||
|
*/
|
||||||
|
let loadedEnvironments = false
|
||||||
|
|
||||||
|
async function writeEnvironments(environment: Environment[]) {
|
||||||
|
if (currentUser$.value == null)
|
||||||
|
throw new Error("Cannot write environments when signed out")
|
||||||
|
|
||||||
|
const ev = {
|
||||||
|
updatedOn: new Date(),
|
||||||
|
author: currentUser$.value.uid,
|
||||||
|
author_name: currentUser$.value.displayName,
|
||||||
|
author_image: currentUser$.value.photoURL,
|
||||||
|
environment,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection("environments")
|
||||||
|
.doc("sync")
|
||||||
|
.set(ev)
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error updating", ev, e)
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initEnvironments() {
|
||||||
|
environments$.subscribe((envs) => {
|
||||||
|
if (
|
||||||
|
currentUser$.value &&
|
||||||
|
settingsStore.value.syncEnvironments &&
|
||||||
|
loadedEnvironments
|
||||||
|
) {
|
||||||
|
writeEnvironments(envs)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let snapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
|
currentUser$.subscribe((user) => {
|
||||||
|
if (!user && snapshotStop) {
|
||||||
|
// User logged out, clean up snapshot listener
|
||||||
|
snapshotStop()
|
||||||
|
snapshotStop = null
|
||||||
|
} else if (user) {
|
||||||
|
snapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.collection("environments")
|
||||||
|
.onSnapshot((environmentsRef) => {
|
||||||
|
const environments: any[] = []
|
||||||
|
|
||||||
|
environmentsRef.forEach((doc) => {
|
||||||
|
const environment = doc.data()
|
||||||
|
environment.id = doc.id
|
||||||
|
environments.push(environment)
|
||||||
|
})
|
||||||
|
|
||||||
|
loadedEnvironments = false
|
||||||
|
replaceEnvironments(environments[0].environment)
|
||||||
|
loadedEnvironments = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
201
helpers/fb/history.ts
Normal file
201
helpers/fb/history.ts
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
import firebase from "firebase"
|
||||||
|
import { currentUser$ } from "./auth"
|
||||||
|
import { settingsStore } from "~/newstore/settings"
|
||||||
|
import {
|
||||||
|
graphqlHistoryStore,
|
||||||
|
HISTORY_LIMIT,
|
||||||
|
restHistoryStore,
|
||||||
|
setGraphqlHistoryEntries,
|
||||||
|
setRESTHistoryEntries,
|
||||||
|
} from "~/newstore/history"
|
||||||
|
|
||||||
|
type HistoryFBCollections = "history" | "graphqlHistory"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the history are loaded. If this is set to true
|
||||||
|
* Updates to the history store are written into firebase.
|
||||||
|
*
|
||||||
|
* If you have want to update the store and not fire the store update
|
||||||
|
* subscription, set this variable to false, do the update and then
|
||||||
|
* set it to true
|
||||||
|
*/
|
||||||
|
let loadedRESTHistory = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the history are loaded. If this is set to true
|
||||||
|
* Updates to the history store are written into firebase.
|
||||||
|
*
|
||||||
|
* If you have want to update the store and not fire the store update
|
||||||
|
* subscription, set this variable to false, do the update and then
|
||||||
|
* set it to true
|
||||||
|
*/
|
||||||
|
let loadedGraphqlHistory = false
|
||||||
|
|
||||||
|
async function writeHistory(entry: any, col: HistoryFBCollections) {
|
||||||
|
if (currentUser$.value == null)
|
||||||
|
throw new Error("User not logged in to sync history")
|
||||||
|
|
||||||
|
const hs = entry
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection(col)
|
||||||
|
.add(hs)
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error writing to history", hs, e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteHistory(entry: any, col: HistoryFBCollections) {
|
||||||
|
if (currentUser$.value == null)
|
||||||
|
throw new Error("User not logged in to delete history")
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection(col)
|
||||||
|
.doc(entry.id)
|
||||||
|
.delete()
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error deleting history", entry, e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearHistory(col: HistoryFBCollections) {
|
||||||
|
if (currentUser$.value == null)
|
||||||
|
throw new Error("User not logged in to clear history")
|
||||||
|
|
||||||
|
const { docs } = await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection(col)
|
||||||
|
.get()
|
||||||
|
|
||||||
|
await Promise.all(docs.map((e) => deleteHistory(e, col)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleStar(entry: any, col: HistoryFBCollections) {
|
||||||
|
if (currentUser$.value == null)
|
||||||
|
throw new Error("User not logged in to toggle star")
|
||||||
|
|
||||||
|
console.log(entry)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection(col)
|
||||||
|
.doc(entry.id)
|
||||||
|
.update({ star: !entry.star })
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error toggling star", entry, e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initHistory() {
|
||||||
|
restHistoryStore.dispatches$.subscribe((dispatch) => {
|
||||||
|
if (
|
||||||
|
loadedRESTHistory &&
|
||||||
|
currentUser$.value &&
|
||||||
|
settingsStore.value.syncHistory
|
||||||
|
) {
|
||||||
|
if (dispatch.dispatcher === "addEntry") {
|
||||||
|
writeHistory(dispatch.payload.entry, "history")
|
||||||
|
} else if (dispatch.dispatcher === "deleteEntry") {
|
||||||
|
deleteHistory(dispatch.payload.entry, "history")
|
||||||
|
} else if (dispatch.dispatcher === "clearHistory") {
|
||||||
|
clearHistory("history")
|
||||||
|
} else if (dispatch.dispatcher === "toggleStar") {
|
||||||
|
toggleStar(dispatch.payload.entry, "history")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
graphqlHistoryStore.dispatches$.subscribe((dispatch) => {
|
||||||
|
if (
|
||||||
|
loadedGraphqlHistory &&
|
||||||
|
currentUser$.value &&
|
||||||
|
settingsStore.value.syncHistory
|
||||||
|
) {
|
||||||
|
if (dispatch.dispatcher === "addEntry") {
|
||||||
|
writeHistory(dispatch.payload.entry, "graphqlHistory")
|
||||||
|
} else if (dispatch.dispatcher === "deleteEntry") {
|
||||||
|
deleteHistory(dispatch.payload.entry, "graphqlHistory")
|
||||||
|
} else if (dispatch.dispatcher === "clearHistory") {
|
||||||
|
clearHistory("graphqlHistory")
|
||||||
|
} else if (dispatch.dispatcher === "toggleStar") {
|
||||||
|
toggleStar(dispatch.payload.entry, "graphqlHistory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let restSnapshotStop: (() => void) | null = null
|
||||||
|
let graphqlSnapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
|
currentUser$.subscribe((user) => {
|
||||||
|
if (!user) {
|
||||||
|
// Clear the snapshot listeners when the user logs out
|
||||||
|
if (restSnapshotStop) {
|
||||||
|
restSnapshotStop()
|
||||||
|
restSnapshotStop = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graphqlSnapshotStop) {
|
||||||
|
graphqlSnapshotStop()
|
||||||
|
graphqlSnapshotStop = null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restSnapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.collection("history")
|
||||||
|
.orderBy("updatedOn", "desc")
|
||||||
|
.limit(HISTORY_LIMIT)
|
||||||
|
.onSnapshot((historyRef) => {
|
||||||
|
const history: any[] = []
|
||||||
|
|
||||||
|
historyRef.forEach((doc) => {
|
||||||
|
const entry = doc.data()
|
||||||
|
entry.id = doc.id
|
||||||
|
history.push(entry)
|
||||||
|
})
|
||||||
|
|
||||||
|
loadedRESTHistory = false
|
||||||
|
setRESTHistoryEntries(history)
|
||||||
|
loadedRESTHistory = true
|
||||||
|
})
|
||||||
|
|
||||||
|
graphqlSnapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.collection("graphqlHistory")
|
||||||
|
.orderBy("updatedOn", "desc")
|
||||||
|
.limit(HISTORY_LIMIT)
|
||||||
|
.onSnapshot((historyRef) => {
|
||||||
|
const history: any[] = []
|
||||||
|
|
||||||
|
historyRef.forEach((doc) => {
|
||||||
|
const entry = doc.data()
|
||||||
|
entry.id = doc.id
|
||||||
|
history.push(entry)
|
||||||
|
})
|
||||||
|
|
||||||
|
loadedGraphqlHistory = false
|
||||||
|
setGraphqlHistoryEntries(history)
|
||||||
|
loadedGraphqlHistory = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
33
helpers/fb/index.ts
Normal file
33
helpers/fb/index.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import firebase from "firebase"
|
||||||
|
import { initAuth } from "./auth"
|
||||||
|
import { initCollections } from "./collections"
|
||||||
|
import { initEnvironments } from "./environments"
|
||||||
|
import { initHistory } from "./history"
|
||||||
|
import { initSettings } from "./settings"
|
||||||
|
|
||||||
|
const firebaseConfig = {
|
||||||
|
apiKey: process.env.API_KEY,
|
||||||
|
authDomain: process.env.AUTH_DOMAIN,
|
||||||
|
databaseURL: process.env.DATABASE_URL,
|
||||||
|
projectId: process.env.PROJECT_ID,
|
||||||
|
storageBucket: process.env.STORAGE_BUCKET,
|
||||||
|
messagingSenderId: process.env.MESSAGING_SENDER_ID,
|
||||||
|
appId: process.env.APP_ID,
|
||||||
|
measurementId: process.env.MEASUREMENT_ID,
|
||||||
|
}
|
||||||
|
|
||||||
|
let initialized = false
|
||||||
|
|
||||||
|
export function initializeFirebase() {
|
||||||
|
if (!initialized) {
|
||||||
|
firebase.initializeApp(firebaseConfig)
|
||||||
|
|
||||||
|
initAuth()
|
||||||
|
initSettings()
|
||||||
|
initCollections()
|
||||||
|
initHistory()
|
||||||
|
initEnvironments()
|
||||||
|
|
||||||
|
initialized = true
|
||||||
|
}
|
||||||
|
}
|
||||||
92
helpers/fb/settings.ts
Normal file
92
helpers/fb/settings.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import firebase from "firebase"
|
||||||
|
import { currentUser$ } from "./auth"
|
||||||
|
import { applySetting, settingsStore, SettingsType } from "~/newstore/settings"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used locally to prevent infinite loop when settings sync update
|
||||||
|
* is applied to the store which then fires the store sync listener.
|
||||||
|
* When you want to update settings and not want to fire the update listener,
|
||||||
|
* set this to true and then set it back to false once it is done
|
||||||
|
*/
|
||||||
|
let loadedSettings = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write Transform
|
||||||
|
*/
|
||||||
|
async function writeSettings(setting: string, value: any) {
|
||||||
|
if (currentUser$.value === null)
|
||||||
|
throw new Error("Cannot write setting, user not signed in")
|
||||||
|
|
||||||
|
const st = {
|
||||||
|
updatedOn: new Date(),
|
||||||
|
author: currentUser$.value.uid,
|
||||||
|
author_name: currentUser$.value.displayName,
|
||||||
|
author_image: currentUser$.value.photoURL,
|
||||||
|
name: setting,
|
||||||
|
value,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(currentUser$.value.uid)
|
||||||
|
.collection("settings")
|
||||||
|
.doc(setting)
|
||||||
|
.set(st)
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error updating", st, e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initSettings() {
|
||||||
|
settingsStore.dispatches$.subscribe((dispatch) => {
|
||||||
|
if (currentUser$.value && loadedSettings) {
|
||||||
|
if (dispatch.dispatcher === "bulkApplySettings") {
|
||||||
|
Object.keys(dispatch.payload).forEach((key) => {
|
||||||
|
writeSettings(key, dispatch.payload[key])
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
writeSettings(
|
||||||
|
dispatch.payload.settingKey,
|
||||||
|
settingsStore.value[dispatch.payload.settingKey as keyof SettingsType]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let snapshotStop: (() => void) | null = null
|
||||||
|
|
||||||
|
// Subscribe and unsubscribe event listeners
|
||||||
|
currentUser$.subscribe((user) => {
|
||||||
|
if (!user && snapshotStop) {
|
||||||
|
// User logged out
|
||||||
|
snapshotStop()
|
||||||
|
snapshotStop = null
|
||||||
|
} else if (user) {
|
||||||
|
snapshotStop = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.doc(user.uid)
|
||||||
|
.collection("settings")
|
||||||
|
.onSnapshot((settingsRef) => {
|
||||||
|
const settings: any[] = []
|
||||||
|
|
||||||
|
settingsRef.forEach((doc) => {
|
||||||
|
const setting = doc.data()
|
||||||
|
setting.id = doc.id
|
||||||
|
settings.push(setting)
|
||||||
|
})
|
||||||
|
|
||||||
|
loadedSettings = false
|
||||||
|
settings.forEach((e) => {
|
||||||
|
if (e && e.name && e.value != null) {
|
||||||
|
applySetting(e.name, e.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
loadedSettings = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BehaviorSubject } from "rxjs"
|
import { BehaviorSubject } from "rxjs"
|
||||||
import gql from "graphql-tag"
|
import gql from "graphql-tag"
|
||||||
import { fb } from "../fb"
|
import { authIdToken$ } from "../fb/auth"
|
||||||
import { apolloClient } from "../apollo"
|
import { apolloClient } from "../apollo"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -11,7 +11,7 @@ import { apolloClient } from "../apollo"
|
|||||||
/**
|
/**
|
||||||
* Defines the information provided about a user
|
* Defines the information provided about a user
|
||||||
*/
|
*/
|
||||||
interface UserInfo {
|
export interface UserInfo {
|
||||||
/**
|
/**
|
||||||
* UID of the user
|
* UID of the user
|
||||||
*/
|
*/
|
||||||
@@ -42,10 +42,8 @@ export const currentUserInfo$ = new BehaviorSubject<UserInfo | null>(null)
|
|||||||
/**
|
/**
|
||||||
* Initializes the currenUserInfo$ view and sets up its update mechanism
|
* Initializes the currenUserInfo$ view and sets up its update mechanism
|
||||||
*/
|
*/
|
||||||
export async function initUserInfo() {
|
export function initUserInfo() {
|
||||||
if (fb.idToken) await updateUserInfo()
|
authIdToken$.subscribe((token) => {
|
||||||
|
|
||||||
fb.idToken$.subscribe((token) => {
|
|
||||||
if (token) {
|
if (token) {
|
||||||
updateUserInfo()
|
updateUserInfo()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -263,10 +263,7 @@
|
|||||||
"syncCollections": "সংগ্রহ",
|
"syncCollections": "সংগ্রহ",
|
||||||
"syncEnvironments": "এনভায়রনমেন্টসমূহ",
|
"syncEnvironments": "এনভায়রনমেন্টসমূহ",
|
||||||
"turn_on": "চালু করুন",
|
"turn_on": "চালু করুন",
|
||||||
"login_first": "প্রথমে লগিন করুন",
|
|
||||||
"paste_a_note": "একটি মন্তব্য লিপিবদ্ধ করুন",
|
|
||||||
"import_from_sync": "সিঙ্ক থেকে ইমপোর্ট করুন",
|
"import_from_sync": "সিঙ্ক থেকে ইমপোর্ট করুন",
|
||||||
"notes": "মন্তব্য",
|
|
||||||
"socketio": "সকেট ইনপুট/আউটপুট",
|
"socketio": "সকেট ইনপুট/আউটপুট",
|
||||||
"event_name": "ইভেন্টের নাম",
|
"event_name": "ইভেন্টের নাম",
|
||||||
"mqtt": "এম.কিউ.টি.টি",
|
"mqtt": "এম.কিউ.টি.টি",
|
||||||
|
|||||||
@@ -90,10 +90,7 @@
|
|||||||
"syncEnvironments": "Environments",
|
"syncEnvironments": "Environments",
|
||||||
"turn_on": "Anschalten",
|
"turn_on": "Anschalten",
|
||||||
"turn_off": "Ausschalten",
|
"turn_off": "Ausschalten",
|
||||||
"login_first": "Logge dich zuerst ein",
|
|
||||||
"paste_a_note": "Füge eine Notiz hinzu",
|
|
||||||
"import_from_sync": "Von Sync importieren",
|
"import_from_sync": "Von Sync importieren",
|
||||||
"notes": "Notizen",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Event Name",
|
"event_name": "Event Name",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -266,10 +266,7 @@
|
|||||||
"syncEnvironments": "Environments",
|
"syncEnvironments": "Environments",
|
||||||
"turn_on": "Turn on",
|
"turn_on": "Turn on",
|
||||||
"turn_off": "Turn off",
|
"turn_off": "Turn off",
|
||||||
"login_first": "Login first",
|
|
||||||
"paste_a_note": "Paste a note",
|
|
||||||
"import_from_sync": "Import from Sync",
|
"import_from_sync": "Import from Sync",
|
||||||
"notes": "Notes",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Event Name",
|
"event_name": "Event Name",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -240,7 +240,6 @@
|
|||||||
"syncCollections": "Colecciones",
|
"syncCollections": "Colecciones",
|
||||||
"syncEnvironments": "Entornos",
|
"syncEnvironments": "Entornos",
|
||||||
"turn_on": "Encender",
|
"turn_on": "Encender",
|
||||||
"login_first": "Inicie sesión primero",
|
|
||||||
"import_from_sync": "Importar desde Sync",
|
"import_from_sync": "Importar desde Sync",
|
||||||
"add_one_variable": "(añade al menos una variable)",
|
"add_one_variable": "(añade al menos una variable)",
|
||||||
"check_graphql_valid": "Compruebe la URL para ver si es un endpoint GraphQL válido",
|
"check_graphql_valid": "Compruebe la URL para ver si es un endpoint GraphQL válido",
|
||||||
@@ -262,8 +261,6 @@
|
|||||||
"scrollInto_use_toggle": "Auto scroll",
|
"scrollInto_use_toggle": "Auto scroll",
|
||||||
"prettify_query": "Formatear query",
|
"prettify_query": "Formatear query",
|
||||||
"prettify_body": "Formatear cuerpo",
|
"prettify_body": "Formatear cuerpo",
|
||||||
"paste_a_note": "Pegar una nota",
|
|
||||||
"notes": "Notas",
|
|
||||||
"new_environment": "Nuevo entorno",
|
"new_environment": "Nuevo entorno",
|
||||||
"my_new_environment": "Mi nuevo entorno",
|
"my_new_environment": "Mi nuevo entorno",
|
||||||
"mqtt_unsubscribe": "Desuscribirse",
|
"mqtt_unsubscribe": "Desuscribirse",
|
||||||
|
|||||||
@@ -241,7 +241,6 @@
|
|||||||
"syncCollections": "Collections",
|
"syncCollections": "Collections",
|
||||||
"syncEnvironments": "Environments",
|
"syncEnvironments": "Environments",
|
||||||
"turn_on": "Activer",
|
"turn_on": "Activer",
|
||||||
"login_first": "Se connecter d'abord",
|
|
||||||
"paste_a_collection": "Coller une collection",
|
"paste_a_collection": "Coller une collection",
|
||||||
"import_from_sync": "Importer depuis la synchronisation",
|
"import_from_sync": "Importer depuis la synchronisation",
|
||||||
"create_new_collection": "Créer une nouvelle collection",
|
"create_new_collection": "Créer une nouvelle collection",
|
||||||
|
|||||||
@@ -263,10 +263,7 @@
|
|||||||
"syncEnvironments": "Lingkungan",
|
"syncEnvironments": "Lingkungan",
|
||||||
"turn_on": "Nyalakan",
|
"turn_on": "Nyalakan",
|
||||||
"turn_off": "Matikan",
|
"turn_off": "Matikan",
|
||||||
"login_first": "Masuk dahulu",
|
|
||||||
"paste_a_note": "Tempel catatan",
|
|
||||||
"import_from_sync": "Impor dari Sinkronasi",
|
"import_from_sync": "Impor dari Sinkronasi",
|
||||||
"notes": "Catatan",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Nama Kejadian",
|
"event_name": "Nama Kejadian",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -266,10 +266,7 @@
|
|||||||
"syncEnvironments": "वातावरण",
|
"syncEnvironments": "वातावरण",
|
||||||
"turn_on": "चालू करो",
|
"turn_on": "चालू करो",
|
||||||
"turn_off": "बंद करें",
|
"turn_off": "बंद करें",
|
||||||
"login_first": "पहले प्रवेश करो",
|
|
||||||
"paste_a_note": "एक नोट चिपकाएं",
|
|
||||||
"import_from_sync": "सिंक से आयात करें",
|
"import_from_sync": "सिंक से आयात करें",
|
||||||
"notes": "टिप्पणियाँ",
|
|
||||||
"socketio": "सॉकेट.आईओ",
|
"socketio": "सॉकेट.आईओ",
|
||||||
"event_name": "घटना नाम",
|
"event_name": "घटना नाम",
|
||||||
"mqtt": "एमक्यूटीटी",
|
"mqtt": "एमक्यूटीटी",
|
||||||
|
|||||||
@@ -263,10 +263,7 @@
|
|||||||
"syncCollections": "컬렉션",
|
"syncCollections": "컬렉션",
|
||||||
"syncEnvironments": "환경변수",
|
"syncEnvironments": "환경변수",
|
||||||
"turn_on": "Turn on",
|
"turn_on": "Turn on",
|
||||||
"login_first": "먼저 로그인해주세요.",
|
|
||||||
"paste_a_note": "노트 붙여넣기",
|
|
||||||
"import_from_sync": "동기화에서 가져오기",
|
"import_from_sync": "동기화에서 가져오기",
|
||||||
"notes": "노트",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "이",
|
"event_name": "이",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -263,10 +263,7 @@
|
|||||||
"syncCollections": "ശേഖരങ്ങൾ",
|
"syncCollections": "ശേഖരങ്ങൾ",
|
||||||
"syncEnvironments": "പരിതസ്ഥിതികൾ",
|
"syncEnvironments": "പരിതസ്ഥിതികൾ",
|
||||||
"turn_on": "ഓൺ ചെയ്യുക",
|
"turn_on": "ഓൺ ചെയ്യുക",
|
||||||
"login_first": "ആദ്യം പ്രവേശിക്കുക",
|
|
||||||
"paste_a_note": "ഒരു കുറിപ്പ് ഒട്ടിക്കുക",
|
|
||||||
"import_from_sync": "Sync-ൽ നിന്ന് ഇറക്കുമതി ചെയ്യുക",
|
"import_from_sync": "Sync-ൽ നിന്ന് ഇറക്കുമതി ചെയ്യുക",
|
||||||
"notes": "കുറിപ്പുകൾ",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "ഇവന്റിന്റെ പേര്",
|
"event_name": "ഇവന്റിന്റെ പേര്",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -266,10 +266,7 @@
|
|||||||
"syncEnvironments": "Miljøer",
|
"syncEnvironments": "Miljøer",
|
||||||
"turn_on": "Slå på",
|
"turn_on": "Slå på",
|
||||||
"turn_off": "Slå av",
|
"turn_off": "Slå av",
|
||||||
"login_first": "Logg inn først",
|
|
||||||
"paste_a_note": "Lim inn et notat",
|
|
||||||
"import_from_sync": "Importer fra synkronisering",
|
"import_from_sync": "Importer fra synkronisering",
|
||||||
"notes": "Notater",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Hendelsesnavn",
|
"event_name": "Hendelsesnavn",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -263,10 +263,7 @@
|
|||||||
"syncCollections": "Collecties",
|
"syncCollections": "Collecties",
|
||||||
"syncEnvironments": "Omgevingen",
|
"syncEnvironments": "Omgevingen",
|
||||||
"turn_on": "Inschakelen",
|
"turn_on": "Inschakelen",
|
||||||
"login_first": "Meld u eerst aan",
|
|
||||||
"paste_a_note": "Notitie plakken",
|
|
||||||
"import_from_sync": "Importeren van Sync",
|
"import_from_sync": "Importeren van Sync",
|
||||||
"notes": "Notities",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Event-naam",
|
"event_name": "Event-naam",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -271,10 +271,7 @@
|
|||||||
"scrollInto_use_toggle": "Auto rolagem",
|
"scrollInto_use_toggle": "Auto rolagem",
|
||||||
"sync": "Sincronizar",
|
"sync": "Sincronizar",
|
||||||
"turn_on": "Ligar",
|
"turn_on": "Ligar",
|
||||||
"login_first": "Realize o login primeiro",
|
|
||||||
"paste_a_note": "Cole uma nota",
|
|
||||||
"import_from_sync": "Importar de Sincronização",
|
"import_from_sync": "Importar de Sincronização",
|
||||||
"notes": "Notas",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Nome do Evento",
|
"event_name": "Nome do Evento",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -260,10 +260,7 @@
|
|||||||
"syncCollections": "Coleções",
|
"syncCollections": "Coleções",
|
||||||
"syncEnvironments": "Ambientes",
|
"syncEnvironments": "Ambientes",
|
||||||
"turn_on": "Ativar",
|
"turn_on": "Ativar",
|
||||||
"login_first": "Entre primeiro",
|
|
||||||
"paste_a_note": "Cole uma nota",
|
|
||||||
"import_from_sync": "Importar from Sync",
|
"import_from_sync": "Importar from Sync",
|
||||||
"notes": "Notas",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Nome do evento",
|
"event_name": "Nome do evento",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -261,10 +261,7 @@
|
|||||||
"syncCollections": "Koleksiyonlar",
|
"syncCollections": "Koleksiyonlar",
|
||||||
"syncEnvironments": "Ortamlar",
|
"syncEnvironments": "Ortamlar",
|
||||||
"turn_on": "Aç",
|
"turn_on": "Aç",
|
||||||
"login_first": "Önce Giriş Yap",
|
|
||||||
"paste_a_note": "Bir not yapıştır",
|
|
||||||
"import_from_sync": "Senkronizasyondan İçeri Aktar",
|
"import_from_sync": "Senkronizasyondan İçeri Aktar",
|
||||||
"notes": "Notlar",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Olay Adı",
|
"event_name": "Olay Adı",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -263,10 +263,7 @@
|
|||||||
"syncCollections": "Bộ sưu tập",
|
"syncCollections": "Bộ sưu tập",
|
||||||
"syncEnvironments": "Môi trường",
|
"syncEnvironments": "Môi trường",
|
||||||
"turn_on": "Bật",
|
"turn_on": "Bật",
|
||||||
"login_first": "Đăng nhập trước",
|
|
||||||
"paste_a_note": "Dán ghi chú",
|
|
||||||
"import_from_sync": "Nhập từ đồng bồ",
|
"import_from_sync": "Nhập từ đồng bồ",
|
||||||
"notes": "Ghi chú",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Tên Event",
|
"event_name": "Tên Event",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -268,10 +268,7 @@
|
|||||||
"syncEnvironments": "环境",
|
"syncEnvironments": "环境",
|
||||||
"turn_on": "点击开启",
|
"turn_on": "点击开启",
|
||||||
"turn_off": "点击关闭",
|
"turn_off": "点击关闭",
|
||||||
"login_first": "请先登录:",
|
|
||||||
"paste_a_note": "输入新便笺",
|
|
||||||
"import_from_sync": "从云存储导入",
|
"import_from_sync": "从云存储导入",
|
||||||
"notes": "便笺",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "事件名称",
|
"event_name": "事件名称",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -258,10 +258,7 @@
|
|||||||
"syncCollections": "收藏庫",
|
"syncCollections": "收藏庫",
|
||||||
"syncEnvironments": "環境",
|
"syncEnvironments": "環境",
|
||||||
"turn_on": "打開",
|
"turn_on": "打開",
|
||||||
"login_first": "請先登入",
|
|
||||||
"paste_a_note": "Paste a note",
|
|
||||||
"import_from_sync": "Import from Sync",
|
"import_from_sync": "Import from Sync",
|
||||||
"notes": "Notes",
|
|
||||||
"socketio": "Socket.IO",
|
"socketio": "Socket.IO",
|
||||||
"event_name": "Event Name",
|
"event_name": "Event Name",
|
||||||
"mqtt": "MQTT",
|
"mqtt": "MQTT",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { setupLocalPersistence } from "~/newstore/localpersistence"
|
|||||||
import { performMigrations } from "~/helpers/migrations"
|
import { performMigrations } from "~/helpers/migrations"
|
||||||
import { initUserInfo } from "~/helpers/teams/BackendUserInfo"
|
import { initUserInfo } from "~/helpers/teams/BackendUserInfo"
|
||||||
import { registerApolloAuthUpdate } from "~/helpers/apollo"
|
import { registerApolloAuthUpdate } from "~/helpers/apollo"
|
||||||
|
import { initializeFirebase } from "~/helpers/fb"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
@@ -62,6 +63,7 @@ export default {
|
|||||||
|
|
||||||
setupLocalPersistence()
|
setupLocalPersistence()
|
||||||
|
|
||||||
|
initializeFirebase()
|
||||||
initUserInfo()
|
initUserInfo()
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { initializeFirebase } from "~/helpers/fb"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
error: {
|
error: {
|
||||||
@@ -37,7 +39,9 @@ export default {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeMount() {
|
||||||
|
initializeFirebase()
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
statusCode() {
|
statusCode() {
|
||||||
return (this.error && this.error.statusCode) || 500
|
return (this.error && this.error.statusCode) || 500
|
||||||
|
|||||||
@@ -64,28 +64,17 @@ const dispatchers = defineDispatchers({
|
|||||||
const result: Partial<SettingsType> = {}
|
const result: Partial<SettingsType> = {}
|
||||||
result[settingKey] = value
|
result[settingKey] = value
|
||||||
|
|
||||||
return result
|
|
||||||
},
|
|
||||||
applySettingFB<K extends keyof SettingsType>(
|
|
||||||
_currentState: SettingsType,
|
|
||||||
{ settingKey, value }: { settingKey: K; value: SettingsType[K] }
|
|
||||||
) {
|
|
||||||
if (!validKeys.includes(settingKey)) {
|
|
||||||
console.log(
|
|
||||||
`Ignoring non-existent setting key '${settingKey}' assignment by firebase`
|
|
||||||
)
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: Partial<SettingsType> = {}
|
|
||||||
result[settingKey] = value
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const settingsStore = new DispatchingStore(defaultSettings, dispatchers)
|
export const settingsStore = new DispatchingStore(defaultSettings, dispatchers)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An observable value to make avail all the state information at once
|
||||||
|
*/
|
||||||
|
export const settings$ = settingsStore.subject$.asObservable()
|
||||||
|
|
||||||
export function getSettingSubject<K extends keyof SettingsType>(
|
export function getSettingSubject<K extends keyof SettingsType>(
|
||||||
settingKey: K
|
settingKey: K
|
||||||
): Observable<SettingsType[K]> {
|
): Observable<SettingsType[K]> {
|
||||||
@@ -120,16 +109,3 @@ export function applySetting<K extends keyof SettingsType>(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applySettingFB<K extends keyof SettingsType>(
|
|
||||||
settingKey: K,
|
|
||||||
value: SettingsType[K]
|
|
||||||
) {
|
|
||||||
settingsStore.dispatch({
|
|
||||||
dispatcher: "applySettingFB",
|
|
||||||
payload: {
|
|
||||||
settingKey,
|
|
||||||
value,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -64,18 +64,18 @@
|
|||||||
<div v-else class="row-wrapper">
|
<div v-else class="row-wrapper">
|
||||||
<div
|
<div
|
||||||
v-tooltip.bottom="{
|
v-tooltip.bottom="{
|
||||||
content: !fb.currentUser
|
content: !currentUser
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? $t('login_with_github_to') + $t('create_secret_gist')
|
? $t('login_with_github_to') + $t('create_secret_gist')
|
||||||
: null,
|
: null,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
:disabled="
|
:disabled="
|
||||||
!fb.currentUser
|
!currentUser
|
||||||
? true
|
? true
|
||||||
: fb.currentUser.provider !== 'github.com'
|
: currentUser.provider !== 'github.com'
|
||||||
? true
|
? true
|
||||||
: false
|
: false
|
||||||
"
|
"
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Mustache from "mustache"
|
import Mustache from "mustache"
|
||||||
import { fb } from "~/helpers/fb"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
import DocsTemplate from "~/assets/md/docs.md"
|
import DocsTemplate from "~/assets/md/docs.md"
|
||||||
import folderContents from "~/assets/md/folderContents.md"
|
import folderContents from "~/assets/md/folderContents.md"
|
||||||
import folderBody from "~/assets/md/folderBody.md"
|
import folderBody from "~/assets/md/folderBody.md"
|
||||||
@@ -121,13 +121,17 @@ import folderBody from "~/assets/md/folderBody.md"
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
fb,
|
|
||||||
collectionJSON: "[]",
|
collectionJSON: "[]",
|
||||||
items: [],
|
items: [],
|
||||||
docsMarkdown: "",
|
docsMarkdown: "",
|
||||||
selected: [],
|
selected: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
subscriptions() {
|
||||||
|
return {
|
||||||
|
currentUser: currentUser$,
|
||||||
|
}
|
||||||
|
},
|
||||||
head() {
|
head() {
|
||||||
return {
|
return {
|
||||||
title: `Documentation • Hoppscotch`,
|
title: `Documentation • Hoppscotch`,
|
||||||
@@ -147,7 +151,7 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${fb.currentUser.accessToken}`,
|
Authorization: `token ${this.currentUser.accessToken}`,
|
||||||
Accept: "application/vnd.github.v3+json",
|
Accept: "application/vnd.github.v3+json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,25 +6,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { fb } from "~/helpers/fb"
|
import Vue from "vue"
|
||||||
|
import { initializeFirebase } from "~/helpers/fb"
|
||||||
|
import { isSignInWithEmailLink, signInWithEmailLink } from "~/helpers/fb/auth"
|
||||||
|
|
||||||
export default {
|
export default Vue.extend({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
signingInWithEmail: false,
|
signingInWithEmail: false,
|
||||||
error: null,
|
error: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeMount() {
|
||||||
|
initializeFirebase()
|
||||||
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
if (fb.isSignInWithEmailLink(window.location.href)) {
|
if (isSignInWithEmailLink(window.location.href)) {
|
||||||
this.signingInWithEmail = true
|
this.signingInWithEmail = true
|
||||||
|
|
||||||
let email = window.localStorage.getItem("emailForSignIn")
|
let email = window.localStorage.getItem("emailForSignIn")
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
email = window.prompt("Please provide your email for confirmation")
|
email = window.prompt(
|
||||||
|
"Please provide your email for confirmation"
|
||||||
|
) as string
|
||||||
}
|
}
|
||||||
await fb
|
|
||||||
.signInWithEmailLink(email, window.location.href)
|
await signInWithEmailLink(email, window.location.href)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.localStorage.removeItem("emailForSignIn")
|
window.localStorage.removeItem("emailForSignIn")
|
||||||
this.$router.push({ path: "/" })
|
this.$router.push({ path: "/" })
|
||||||
@@ -38,5 +47,5 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -457,14 +457,6 @@
|
|||||||
<SmartTab :id="'collections'" :label="$t('collections')">
|
<SmartTab :id="'collections'" :label="$t('collections')">
|
||||||
<CollectionsGraphql />
|
<CollectionsGraphql />
|
||||||
</SmartTab>
|
</SmartTab>
|
||||||
|
|
||||||
<!-- <SmartTab :id="'env'" :label="$t('environments')">
|
|
||||||
<Environments @use-environment="useSelectedEnvironment($event)" />
|
|
||||||
</SmartTab>
|
|
||||||
|
|
||||||
<SmartTab :id="'notes'" :label="$t('notes')">
|
|
||||||
<HttpNotes />
|
|
||||||
</SmartTab> -->
|
|
||||||
</SmartTabs>
|
</SmartTabs>
|
||||||
</aside>
|
</aside>
|
||||||
</TranslateSlideLeft>
|
</TranslateSlideLeft>
|
||||||
|
|||||||
@@ -628,10 +628,6 @@
|
|||||||
<SmartTab :id="'env'" :label="$t('environments')">
|
<SmartTab :id="'env'" :label="$t('environments')">
|
||||||
<Environments />
|
<Environments />
|
||||||
</SmartTab>
|
</SmartTab>
|
||||||
|
|
||||||
<SmartTab :id="'notes'" :label="$t('notes')">
|
|
||||||
<HttpNotes />
|
|
||||||
</SmartTab>
|
|
||||||
</SmartTabs>
|
</SmartTabs>
|
||||||
</section>
|
</section>
|
||||||
</aside>
|
</aside>
|
||||||
@@ -766,7 +762,6 @@ import runTestScriptWithVariables from "~/helpers/postwomanTesting"
|
|||||||
import parseTemplateString from "~/helpers/templating"
|
import parseTemplateString from "~/helpers/templating"
|
||||||
import { tokenRequest, oauthRedirect } from "~/helpers/oauth"
|
import { tokenRequest, oauthRedirect } from "~/helpers/oauth"
|
||||||
import { cancelRunningRequest, sendNetworkRequest } from "~/helpers/network"
|
import { cancelRunningRequest, sendNetworkRequest } from "~/helpers/network"
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
import {
|
import {
|
||||||
hasPathParams,
|
hasPathParams,
|
||||||
addPathParamsToVariables,
|
addPathParamsToVariables,
|
||||||
@@ -811,7 +806,6 @@ export default {
|
|||||||
showSaveRequestModal: false,
|
showSaveRequestModal: false,
|
||||||
editRequest: {},
|
editRequest: {},
|
||||||
activeSidebar: true,
|
activeSidebar: true,
|
||||||
fb,
|
|
||||||
customMethod: false,
|
customMethod: false,
|
||||||
files: [],
|
files: [],
|
||||||
filenames: "",
|
filenames: "",
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div v-if="currentUser && currentUser.eaInvited">
|
<div v-if="currentBackendUser && currentBackendUser.eaInvited">
|
||||||
<Teams />
|
<Teams />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AppSection ref="account" :label="$t('account')">
|
<AppSection ref="account" :label="$t('account')">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label>{{ $t("account") }}</label>
|
<label>{{ $t("account") }}</label>
|
||||||
<div v-if="fb.currentUser">
|
<div v-if="currentUser">
|
||||||
<button class="icon">
|
<button class="icon">
|
||||||
<img
|
<img
|
||||||
v-if="fb.currentUser.photoURL"
|
v-if="currentUser.photoURL"
|
||||||
:src="fb.currentUser.photoURL"
|
:src="currentUser.photoURL"
|
||||||
class="w-6 h-6 rounded-full material-icons"
|
class="w-6 h-6 rounded-full material-icons"
|
||||||
/>
|
/>
|
||||||
<i v-else class="material-icons">account_circle</i>
|
<i v-else class="material-icons">account_circle</i>
|
||||||
<span>
|
<span>
|
||||||
{{ fb.currentUser.displayName || $t("nothing_found") }}
|
{{ currentUser.displayName || $t("nothing_found") }}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<br />
|
<br />
|
||||||
<button class="icon">
|
<button class="icon">
|
||||||
<i class="material-icons">email</i>
|
<i class="material-icons">email</i>
|
||||||
<span>
|
<span>
|
||||||
{{ fb.currentUser.email || $t("nothing_found") }}
|
{{ currentUser.email || $t("nothing_found") }}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<br />
|
<br />
|
||||||
@@ -57,13 +57,6 @@
|
|||||||
{{ SYNC_HISTORY ? $t("enabled") : $t("disabled") }}
|
{{ SYNC_HISTORY ? $t("enabled") : $t("disabled") }}
|
||||||
</SmartToggle>
|
</SmartToggle>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p v-if="fb.currentSettings.length !== 3">
|
|
||||||
<button @click="initSettings">
|
|
||||||
<i class="material-icons">sync</i>
|
|
||||||
<span>{{ $t("turn_on") + " " + $t("sync") }}</span>
|
|
||||||
</button>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<label>{{ $t("login_with") }}</label>
|
<label>{{ $t("login_with") }}</label>
|
||||||
@@ -214,7 +207,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from "vue"
|
import Vue from "vue"
|
||||||
import { hasExtensionInstalled } from "../helpers/strategies/ExtensionStrategy"
|
import { hasExtensionInstalled } from "../helpers/strategies/ExtensionStrategy"
|
||||||
import { fb } from "~/helpers/fb"
|
|
||||||
import {
|
import {
|
||||||
getSettingSubject,
|
getSettingSubject,
|
||||||
applySetting,
|
applySetting,
|
||||||
@@ -223,6 +215,7 @@ import {
|
|||||||
} from "~/newstore/settings"
|
} from "~/newstore/settings"
|
||||||
import type { KeysMatching } from "~/types/ts-utils"
|
import type { KeysMatching } from "~/types/ts-utils"
|
||||||
import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
|
import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
|
||||||
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
|
|
||||||
type SettingsType = typeof defaultSettings
|
type SettingsType = typeof defaultSettings
|
||||||
|
|
||||||
@@ -234,7 +227,6 @@ export default Vue.extend({
|
|||||||
: null,
|
: null,
|
||||||
|
|
||||||
doneButton: '<i class="material-icons">done</i>',
|
doneButton: '<i class="material-icons">done</i>',
|
||||||
fb,
|
|
||||||
|
|
||||||
SYNC_COLLECTIONS: true,
|
SYNC_COLLECTIONS: true,
|
||||||
SYNC_ENVIRONMENTS: true,
|
SYNC_ENVIRONMENTS: true,
|
||||||
@@ -247,6 +239,9 @@ export default Vue.extend({
|
|||||||
PROXY_ENABLED: true,
|
PROXY_ENABLED: true,
|
||||||
|
|
||||||
showEmail: false,
|
showEmail: false,
|
||||||
|
|
||||||
|
currentBackendUser: null,
|
||||||
|
currentUser: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscriptions() {
|
subscriptions() {
|
||||||
@@ -268,7 +263,8 @@ export default Vue.extend({
|
|||||||
SYNC_HISTORY: getSettingSubject("syncHistory"),
|
SYNC_HISTORY: getSettingSubject("syncHistory"),
|
||||||
|
|
||||||
// Teams feature flag
|
// Teams feature flag
|
||||||
currentUser: currentUserInfo$,
|
currentBackendUser: currentUserInfo$,
|
||||||
|
currentUser: currentUser$,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
head() {
|
head() {
|
||||||
@@ -311,18 +307,6 @@ export default Vue.extend({
|
|||||||
value: SettingsType[K]
|
value: SettingsType[K]
|
||||||
) {
|
) {
|
||||||
this.applySetting(name, value)
|
this.applySetting(name, value)
|
||||||
|
|
||||||
if (name === "syncCollections" && value) {
|
|
||||||
this.syncCollections()
|
|
||||||
}
|
|
||||||
if (name === "syncEnvironments" && value) {
|
|
||||||
this.syncEnvironments()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
initSettings() {
|
|
||||||
applySetting("syncHistory", true)
|
|
||||||
applySetting("syncCollections", true)
|
|
||||||
applySetting("syncEnvironments", true)
|
|
||||||
},
|
},
|
||||||
resetProxy({ target }: { target: HTMLElement }) {
|
resetProxy({ target }: { target: HTMLElement }) {
|
||||||
applySetting("PROXY_URL", `https://proxy.hoppscotch.io/`)
|
applySetting("PROXY_URL", `https://proxy.hoppscotch.io/`)
|
||||||
@@ -336,30 +320,6 @@ export default Vue.extend({
|
|||||||
1000
|
1000
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
// TODO: Use the new collection store
|
|
||||||
syncCollections(): void {
|
|
||||||
if (fb.currentUser !== null && this.SYNC_COLLECTIONS) {
|
|
||||||
if (this.$store.state.postwoman.collections)
|
|
||||||
fb.writeCollections(
|
|
||||||
JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)),
|
|
||||||
"collections"
|
|
||||||
)
|
|
||||||
if (this.$store.state.postwoman.collectionsGraphql)
|
|
||||||
fb.writeCollections(
|
|
||||||
JSON.parse(
|
|
||||||
JSON.stringify(this.$store.state.postwoman.collectionsGraphql)
|
|
||||||
),
|
|
||||||
"collectionsGraphql"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
syncEnvironments(): void {
|
|
||||||
if (fb.currentUser !== null && this.SYNC_ENVIRONMENTS) {
|
|
||||||
fb.writeEnvironments(
|
|
||||||
JSON.parse(JSON.stringify(this.$store.state.postwoman.environments))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user