Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Fix routing
Acho Arnold7ba6728cf726
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 1b202052..3bdf9354 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -1,19 +1,19 @@-repos:- - repo: https://github.com/tekwizely/pre-commit-golang- rev: v1.0.0-rc.1- hooks:- - id: go-fumpt- - id: go-mod-tidy- - id: go-lint- - id: go-imports- - repo: https://github.com/pre-commit/pre-commit-hooks- rev: v4.4.0- hooks:- - id: check-yaml- - id: end-of-file-fixer- - id: trailing-whitespace-- - repo: https://github.com/pre-commit/mirrors-prettier- rev: v3.0.0-alpha.4- hooks:- - id: prettier+repos:+ - repo: https://github.com/tekwizely/pre-commit-golang+ rev: v1.0.0-rc.1+ hooks:+ - id: go-fumpt+ - id: go-mod-tidy+ - id: go-lint+ - id: go-imports+ - repo: https://github.com/pre-commit/pre-commit-hooks+ rev: v4.4.0+ hooks:+ - id: check-yaml+ - id: end-of-file-fixer+ - id: trailing-whitespace++ - repo: https://github.com/pre-commit/mirrors-prettier+ rev: v3.0.0-alpha.6+ hooks:+ - id: prettierdiff --git a/web/components/FirebaseAuth.vue b/web/components/FirebaseAuth.vueindex a355d859..c53ea9f7 100644--- a/web/components/FirebaseAuth.vue+++ b/web/components/FirebaseAuth.vue@@ -16,6 +16,7 @@import { Vue, Component, Prop } from 'vue-property-decorator'import { ProviderId } from 'firebase/auth'import { auth } from 'firebaseui'+import firebase from 'firebase/compat'import { NotificationRequest } from '~/store'@Component@@ -44,11 +45,18 @@ export default class FirebaseAuth extends Vue {uiConfig(): any {return {callbacks: {- signInSuccessWithAuthResult: () => {+ signInSuccessWithAuthResult: (+ authResult: firebase.auth.UserCredential,+ ) => {this.$store.dispatch('addNotification', {message: 'Login successfull!',type: 'success',} as NotificationRequest)++ this.$store.dispatch('onAuthStateChanged', {+ authUser: authResult.user,+ })+this.$router.push({ path: this.to })return false},@@ -58,7 +66,7 @@ export default class FirebaseAuth extends Vue {this.firebaseUIInitialized = trueconst container = this.$refs.authContainer as HTMLElementArray.from(- container.getElementsByClassName('firebaseui-idp-text-long')+ container.getElementsByClassName('firebaseui-idp-text-long'),).forEach((item: Element) => {item.textContent =item.textContent?.replace('Sign in with', 'Continue with') || nulldiff --git a/web/components/LoadingDashboard.vue b/web/components/LoadingDashboard.vuenew file mode 100644index 00000000..556c749f--- /dev/null+++ b/web/components/LoadingDashboard.vue@@ -0,0 +1,40 @@+<template>+ <v-main>+ <v-container fluid fill-height>+ <v-row align="center" justify="center">+ <v-col+ cols="12"+ md="5"+ xl="3"+ class="text-center mt-16"+ :class="{+ 'px-6': $vuetify.breakpoint.mdAndDown,+ 'px-16': !$vuetify.breakpoint.mdAndDown,+ }"+ >+ <h2 class="text-h4 text--secondary mt-16 mb-4">+ <img+ class="mx-auto d-inline-block"+ :src="require('@/assets/img/logo.svg')"+ style="max-width: 32px"+ alt="httpSMS Logo"+ />+ Loading the httpSMS dashboard+ </h2>+ <v-progress-circular+ indeterminate+ size="160"+ class="mt-8"+ color="primary"+ ></v-progress-circular>+ </v-col>+ </v-row>+ </v-container>+ </v-main>+</template>++<script>+export default {+ name: 'LoadingDashboard',+}+</script>diff --git a/web/layouts/default.vue b/web/layouts/default.vueindex 84d737a0..0be46745 100644--- a/web/layouts/default.vue+++ b/web/layouts/default.vue@@ -19,8 +19,9 @@</template></v-navigation-drawer><v-main :class="{ 'has-drawer': hasDrawer && $vuetify.breakpoint.lgAndUp }">- <Nuxt /><toast></toast>+ <Nuxt v-if="$store.getters.authStateChanged" />+ <loading-dashboard v-else></loading-dashboard></v-main></v-app></template>@@ -39,11 +40,14 @@ export default class DefaultLayout extends Vue {mounted() {// this.startPoller()- setTimeout(() => {- if (this.poller) {- clearInterval(this.poller)- }- }, 60 * 1000 * 60)+ setTimeout(+ () => {+ if (this.poller) {+ clearInterval(this.poller)+ }+ },+ 60 * 1000 * 60,+ )}beforeDestroy(): void {@@ -61,7 +65,7 @@ export default class DefaultLayout extends Vue {setAuthHeader((await this.$fire.auth.currentUser?.getIdToken()) ?? '')promises.push(this.$store.dispatch('loadThreads'),- this.$store.dispatch('getHeartbeat')+ this.$store.dispatch('getHeartbeat'),)}@@ -73,8 +77,8 @@ export default class DefaultLayout extends Vue {promises.push(this.$store.dispatch('loadThreadMessages',- this.$store.getters.getThread.id- )+ this.$store.getters.getThread.id,+ ),)}await Promise.all(promises)diff --git a/web/middleware/auth.ts b/web/middleware/auth.tsindex 57ce6895..9ed9aa8e 100644--- a/web/middleware/auth.ts+++ b/web/middleware/auth.ts@@ -2,10 +2,7 @@ import { Context, Middleware } from '@nuxt/types'const authMiddleware: Middleware = (context: Context) => {if (context.store.getters.getAuthUser === null) {- if (context.store.getters.getNextRoute) {- context.redirect('/login', { to: context.route.path })- context.store.dispatch('setNextRoute', null)- }+ context.redirect('/login', { to: context.route.path })}}diff --git a/web/middleware/guest.ts b/web/middleware/guest.tsindex bb4765a8..d7033821 100644--- a/web/middleware/guest.ts+++ b/web/middleware/guest.ts@@ -2,10 +2,6 @@ import { Context, Middleware } from '@nuxt/types'const guestMiddleware: Middleware = (context: Context) => {if (context.store.getters.getAuthUser !== null) {- if (context.store.getters.getNextRoute) {- context.redirect(context.store.getters.getNextRoute)- context.store.dispatch('setNextRoute', null)- }context.redirect('/threads')}}diff --git a/web/middleware/user.ts b/web/middleware/user.tsdeleted file mode 100644index 5ada17a0..00000000--- a/web/middleware/user.ts+++ /dev/null@@ -1,31 +0,0 @@-import { Context } from '@nuxt/types'-import { User, Auth } from 'firebase/auth'-import { AuthUser as StateUser } from '~/store'-import { setAuthHeader } from '~/plugins/axios'--export default async function (context: Context) {- await setUser(context)-}--const setUser = (context: Context): Promise<User | null> => {- return new Promise((resolve, reject) => {- const unsubscribe = (context.app.$fire.auth as Auth).onAuthStateChanged(- async (user) => {- unsubscribe()- let stateUser: StateUser | null = null- if (user) {- stateUser = {- email: user.email,- displayName: user.displayName,- id: user.uid,- }- setAuthHeader(await user.getIdToken())- }- context.store.dispatch('setAuthUser', stateUser).finally(() => {- resolve(user)- })- },- reject- )- })-}diff --git a/web/nuxt.config.js b/web/nuxt.config.jsindex c4faf75c..1f8769a4 100644--- a/web/nuxt.config.js+++ b/web/nuxt.config.js@@ -112,7 +112,7 @@ export default {persistence: 'local', // defaultinitialize: {onAuthStateChangedAction: 'onAuthStateChanged',- onIdTokenChangedAction: 'onAuthStateChanged',+ onIdTokenChangedAction: 'onIdTokenChanged',subscribeManually: false,},ssr: false,@@ -148,10 +148,6 @@ export default {},},- router: {- middleware: ['user'],- },-sitemap: {hostname: 'https://httpsms.com',gzip: true,diff --git a/web/package.json b/web/package.jsonindex d77c990f..5d114b01 100644--- a/web/package.json+++ b/web/package.json@@ -62,7 +62,7 @@"jest": "^27.4.4","lint-staged": "^13.2.0","postcss-html": "^1.5.0",- "prettier": "^2.8.4",+ "prettier": "3.0.0-alpha.6","stylelint": "^14.16.1","stylelint-config-prettier": "^9.0.5","stylelint-config-recommended-vue": "^1.1.0",diff --git a/web/pages/billing/index.vue b/web/pages/billing/index.vueindex 65c93ab6..16710aaf 100644--- a/web/pages/billing/index.vue+++ b/web/pages/billing/index.vue@@ -1,8 +1,12 @@<template>- <v-container fluid class="pa-0" :fill-height="$vuetify.breakpoint.lgAndUp">+ <v-container+ fluid+ class="px-0 pt-0"+ :fill-height="$vuetify.breakpoint.lgAndUp"+ ><div class="w-full h-full"><v-app-bar height="60" :dense="$vuetify.breakpoint.mdAndDown">- <v-btn icon to="/">+ <v-btn icon to="/threads"><v-icon>{{ mdiArrowLeft }}</v-icon></v-btn><v-toolbar-title>@@ -45,7 +49,7 @@Your next bill is for <b>${{ plan.price }}</b> on<b>{{new Date(- $store.getters.getUser.subscription_renews_at+ $store.getters.getUser.subscription_renews_at,).toLocaleDateString()}}</b></p>@@ -60,7 +64,7 @@You will be downgraded to the <b>FREE</b> plan on<b>{{new Date(- $store.getters.getUser.subscription_ends_at+ $store.getters.getUser.subscription_ends_at,).toLocaleDateString()}}</b></p>@@ -112,7 +116,7 @@of the current billing period on<b>{{new Date(- $store.getters.getUser.subscription_renews_at+ $store.getters.getUser.subscription_renews_at,).toLocaleDateString()}}</b></p>@@ -395,7 +399,7 @@ export default Vue.extend({plan(): PaymentPlan {return this.plans.find((x) =>- x.id === (this.$store.getters.getUser?.subscription_name || 'free')+ x.id === (this.$store.getters.getUser?.subscription_name || 'free'),)!},isOnFreePlan(): boolean {@@ -418,12 +422,6 @@ export default Vue.extend({},},async mounted() {- if (!this.$store.getters.getAuthUser) {- await this.$store.dispatch('setNextRoute', this.$route.path)- await this.$router.push({ name: 'index' })- setTimeout(this.loadData, 2000)- return- }await this.loadData()},diff --git a/web/pages/index.vue b/web/pages/index.vueindex b5e41208..2ae1d23e 100644--- a/web/pages/index.vue+++ b/web/pages/index.vue@@ -553,7 +553,6 @@ import {export default Vue.extend({name: 'LandingPage',layout: 'website',- middleware: ['guest'],data() {return {mdiGithub,diff --git a/web/pages/login.vue b/web/pages/login.vueindex 693fcb5d..7486420b 100644--- a/web/pages/login.vue+++ b/web/pages/login.vue@@ -1,5 +1,5 @@<template>- <v-container fluid class="pa-0" fill-height>+ <v-container fluid fill-height><v-row align="center" justify="center"><v-colcols="12"@@ -39,7 +39,7 @@ export default Vue.extend({middleware: ['guest'],data() {return {- to: '/',+ to: '/threads',}},head() {diff --git a/web/pages/messages/index.vue b/web/pages/messages/index.vueindex 46b6ab91..3406443a 100644--- a/web/pages/messages/index.vue+++ b/web/pages/messages/index.vue@@ -2,7 +2,7 @@<v-container fluid class="pa-0" :fill-height="$vuetify.breakpoint.lgAndUp"><div class="w-full h-full"><v-app-bar height="60" :dense="$vuetify.breakpoint.mdAndDown">- <v-btn icon to="/">+ <v-btn icon to="/threads"><v-icon>{{ mdiArrowLeft }}</v-icon></v-btn><v-toolbar-title>New Message</v-toolbar-title>@@ -96,8 +96,8 @@ export default {errors.set('to',response.data.data.to.map((x) =>- x.replace('to field', 'phone number field')- )+ x.replace('to field', 'phone number field'),+ ),)}if (response.data.data.from) {diff --git a/web/pages/settings/index.vue b/web/pages/settings/index.vueindex d3b71c46..29d2bf60 100644--- a/web/pages/settings/index.vue+++ b/web/pages/settings/index.vue@@ -1,8 +1,12 @@<template>- <v-container fluid class="pa-0" :fill-height="$vuetify.breakpoint.lgAndUp">+ <v-container+ fluid+ class="px-0 pt-0"+ :fill-height="$vuetify.breakpoint.lgAndUp"+ ><div class="w-full h-full"><v-app-bar height="60" :dense="$vuetify.breakpoint.mdAndDown">- <v-btn icon to="/">+ <v-btn icon to="/threads"><v-icon>{{ mdiArrowLeft }}</v-icon></v-btn><v-toolbar-title>@@ -464,12 +468,8 @@ export default Vue.extend({},},mounted() {+ console.log('inside settings')this.$store.dispatch('clearAxiosError')- if (!this.$store.getters.getAuthUser) {- this.$store.dispatch('setNextRoute', this.$route.path)- this.$router.push({ name: 'index' })- return- }this.$store.dispatch('loadUser')this.loadWebhooks()},diff --git a/web/pages/threads/_id.vue b/web/pages/threads/_id.vueindex 408a58ca..0f4fda80 100644--- a/web/pages/threads/_id.vue+++ b/web/pages/threads/_id.vue@@ -1,8 +1,12 @@<template>- <v-container fluid class="pa-0" :fill-height="$vuetify.breakpoint.lgAndUp">+ <v-container+ fluid+ class="px-0 pt-0 pb-0"+ :fill-height="$vuetify.breakpoint.lgAndUp"+ ><div class="w-full h-full"><v-app-bar height="60" :dense="$vuetify.breakpoint.mdAndDown">- <v-btn v-if="$vuetify.breakpoint.mdAndDown" icon to="/">+ <v-btn v-if="$vuetify.breakpoint.mdAndDown" icon to="/threads"><v-icon>{{ mdiArrowLeft }}</v-icon></v-btn><v-toolbar-title>@@ -289,12 +293,6 @@ export default Vue.extend({},async mounted() {- if (!this.$store.getters.getAuthUser) {- await this.$store.dispatch('setNextRoute', this.$route.path)- await this.$router.push({ name: 'index' })- setTimeout(this.loadData, 2000)- return- }await this.loadData()},@@ -377,7 +375,7 @@ export default Vue.extend({await this.$store.dispatch('loadThreadMessages',- this.$store.getters.getThread.id+ this.$store.getters.getThread.id,)this.scrollToElement()diff --git a/web/pages/threads/index.vue b/web/pages/threads/index.vueindex 5f3788e9..09452fae 100644--- a/web/pages/threads/index.vue+++ b/web/pages/threads/index.vue@@ -1,5 +1,5 @@<template>- <v-container fluid class="pa-0" :fill-height="$vuetify.breakpoint.lgAndUp">+ <v-container fluid :fill-height="$vuetify.breakpoint.lgAndUp"><v-row v-if="$vuetify.breakpoint.lgAndUp" align="center" justify="center"><div><v-img@@ -34,12 +34,6 @@ export default {}},async mounted() {- if (!this.$store.getters.getAuthUser) {- await this.$store.dispatch('setNextRoute', this.$route.path)- await this.$router.push({ name: 'index' })- setTimeout(this.loadData, 2000)- return- }await this.loadData()},diff --git a/web/plugins/errors.ts b/web/plugins/errors.tsindex 813c6b63..437b641f 100644--- a/web/plugins/errors.ts+++ b/web/plugins/errors.ts@@ -21,7 +21,7 @@ const sanitize = (key: string, values: Array<string>): Array<string> => {.split(' char').join(' character').split(' field ')- .join(' ')+ .join(' '),)})}diff --git a/web/store/index.ts b/web/store/index.tsindex e7176359..2c35192a 100644--- a/web/store/index.ts+++ b/web/store/index.ts@@ -43,10 +43,10 @@ export type AuthUser = {export type State = {owner: string | nullaxiosError: AxiosError | null- nextRoute: string | nullloadingThreads: booleanloadingMessages: booleanarchivedThreads: boolean+ authStateChanged: booleanauthUser: AuthUser | nullbillingUsage: BillingUsage | nullbillingUsageHistory: Array<BillingUsage>@@ -64,8 +64,8 @@ export const state = (): State => ({threads: [],threadId: null,heartbeat: null,- nextRoute: null,axiosError: null,+ authStateChanged: false,loadingThreads: true,billingUsage: null,billingUsageHistory: [],@@ -126,6 +126,8 @@ export const getters = {return state.axiosError},+ authStateChanged: (state: State) => state.authStateChanged,+isLocal(): boolean {return process.env.APP_ENV === 'local'},@@ -170,10 +172,6 @@ export const getters = {return state.loadingMessages},- getNextRoute(state: State): string | null {- return state.nextRoute- },-getThreadMessages(state: State): Array<Message> {return state.threadMessages},@@ -228,6 +226,7 @@ export const mutations = {state.pooling = payload},setAuthUser(state: State, payload: AuthUser | null) {+ state.authStateChanged = truestate.authUser = payload},setAxiosError(state: State, payload: AxiosError | null) {@@ -282,10 +281,6 @@ export const mutations = {state.archivedThreads = falsestate.owner = null},-- setNextRoute(state: State, payload: string | null) {- state.nextRoute = payload- },}export type SendMessageRequest = {@@ -360,7 +355,7 @@ export const actions = {fcm_token: phone.fcm_token,phone_number: phone.phone_number,message_expiration_seconds: parseInt(- phone.message_expiration_seconds.toString()+ phone.message_expiration_seconds.toString(),),max_send_attempts: parseInt(phone.max_send_attempts.toString()),messages_per_minute: parseInt(phone.messages_per_minute.toString()),@@ -380,7 +375,7 @@ export const actions = {async handleAxiosError(context: ActionContext<State, State>,- error: AxiosError+ error: AxiosError,) {const errorMessage =error.response?.data?.data[Object.keys(error.response?.data?.data)[0]][0]@@ -415,7 +410,7 @@ export const actions = {async sendMessage(context: ActionContext<State, State>,- request: SendMessageRequest+ request: SendMessageRequest,) {try {const response = await axios.post('/v1/messages/send', request)@@ -443,7 +438,7 @@ export const actions = {addNotification(context: ActionContext<State, State>,- request: NotificationRequest+ request: NotificationRequest,) {context.commit('setNotification', request)},@@ -452,13 +447,9 @@ export const actions = {context.commit('disableNotification')},- setNextRoute(context: ActionContext<State, State>, payload: string | null) {- context.commit('setNextRoute', payload)- },-async loadThreadMessages(context: ActionContext<State, State>,- threadId: string | null+ threadId: string | null,) {await context.commit('setThreadId', threadId)const response = await axios.get('/v1/messages', {@@ -473,7 +464,7 @@ export const actions = {async setAuthUser(context: ActionContext<State, State>,- user: AuthUser | null | undefined+ user: AuthUser | null | undefined,) {const userChanged = user?.id !== context.getters.getAuthUser?.id@@ -490,7 +481,7 @@ export const actions = {])const phone = context.getters.getPhones.find(- (x: Phone) => x.id === context.getters.getUser.active_phone_id+ (x: Phone) => x.id === context.getters.getUser.active_phone_id,)if (phone) {await context.dispatch('setOwner', phone.phone_number)@@ -500,16 +491,31 @@ export const actions = {async onAuthStateChanged(context: ActionContext<State, State>,// @ts-ignore- { authUser }+ { authUser },) {if (authUser == null) {- context.commit('setAuthUser', null)- context.commit('setUser', null)+ await Promise.all([+ context.commit('setAuthUser', null),+ context.commit('setUser', null),+ ])return}setAuthHeader(await authUser.getIdToken())const { uid, email, displayName } = authUser- await context.commit('setAuthUser', { id: uid, email, displayName })+ await Promise.all([+ context.commit('setAuthUser', { id: uid, email, displayName }),+ ])+ },++ async onIdTokenChanged(+ _: ActionContext<State, State>,+ // @ts-ignore+ { authUser },+ ) {+ if (authUser == null) {+ return+ }+ setAuthHeader(await authUser.getIdToken())},async clearAxiosError(context: ActionContext<State, State>) {@@ -533,7 +539,7 @@ export const actions = {async updateThread(context: ActionContext<State, State>,- payload: { threadId: string; isArchived: boolean }+ payload: { threadId: string; isArchived: boolean },) {await axios.put(`/v1/message-threads/${payload.threadId}`, {is_archived: payload.isArchived,@@ -586,7 +592,7 @@ export const actions = {createWebhook(context: ActionContext<State, State>,- payload: RequestsWebhookStore+ payload: RequestsWebhookStore,) {return new Promise<EntitiesWebhook>((resolve, reject) => {axios@@ -634,7 +640,7 @@ export const actions = {updateWebhook(context: ActionContext<State, State>,- payload: RequestsWebhookUpdate & { id: string }+ payload: RequestsWebhookUpdate & { id: string },) {return new Promise<EntitiesWebhook>((resolve, reject) => {axiosdiff --git a/web/yarn.lock b/web/yarn.lockindex e9f7ed0f..eb7a2ba0 100644--- a/web/yarn.lock+++ b/web/yarn.lock@@ -11398,7 +11398,12 @@ prepend-http@^1.0.0:resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"integrity sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==-"prettier@^1.18.2 || ^2.0.0", prettier@^2.8.4:+ version "3.0.0-alpha.6"+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.0-alpha.6.tgz#c562f9f54966aff792c6920e6a29fbffd1ae07b6"+ integrity sha512-AdbQSZ6Oo+iy9Ekzmsgno05P1uX2vqPkjOMJqRfP8hTe+m6iDw4Nt7bPFpWZ/HYCU+3f0P5U0o2ghxQwwkLH7A==++"prettier@^1.18.2 || ^2.0.0":version "2.8.4"resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==