Google Sheet - OAuth "client" powered integrations (#415)
* fix `helpers.php` * fix `.eslintrc.cjs` * spreadsheet manager * fetch providers. set `oauth_id` for integrations * create spreadsheet on integration create event * connect OAuth accounts * display actions. connect account if missing * cleanup * handle form field change * map integration data object to `SpreadsheetData` * validate request * wip * redirect to integrations page * fix refresh token * add helper text * add extra integration info * refactor * refresh google token * fix validation * add tests * Fix linting issue * Update composer lock file --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
57
client/stores/oauth_providers.js
vendored
Normal file
57
client/stores/oauth_providers.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import { defineStore } from "pinia"
|
||||
import { useContentStore } from "~/composables/stores/useContentStore.js"
|
||||
|
||||
export const providersEndpoint = "/open/providers"
|
||||
|
||||
export const useOAuthProvidersStore = defineStore("oauth_providers", () => {
|
||||
const contentStore = useContentStore()
|
||||
const alert = useAlert()
|
||||
|
||||
const fetchOAuthProviders = () => {
|
||||
contentStore.resetState()
|
||||
contentStore.startLoading()
|
||||
|
||||
return opnFetch(providersEndpoint).then(
|
||||
(data) => {
|
||||
contentStore.save(data)
|
||||
contentStore.stopLoading()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const connect = (service, redirect = false) => {
|
||||
contentStore.resetState()
|
||||
contentStore.startLoading()
|
||||
|
||||
const intention = new URL(window.location.href).pathname
|
||||
|
||||
opnFetch(`/settings/providers/connect/${service}`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
...redirect ? { intention } : {},
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
window.location.href = data.url
|
||||
})
|
||||
.catch((error) => {
|
||||
try {
|
||||
alert.error(error.data.message)
|
||||
} catch (e) {
|
||||
alert.error("An error occurred while connecting an account")
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
contentStore.stopLoading()
|
||||
})
|
||||
}
|
||||
|
||||
const providers = computed(() => contentStore.getAll.value)
|
||||
|
||||
return {
|
||||
...contentStore,
|
||||
fetchOAuthProviders,
|
||||
providers,
|
||||
connect
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user