Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
feat(web): migrate to modular Firebase SDK and use Vuetify 4 default breakpoints
Acho Arnold3c5931c30d50
diff --git a/web/app/components/FirebaseAuth.vue b/web/app/components/FirebaseAuth.vueindex db0f18e6..47717acb 100644--- a/web/app/components/FirebaseAuth.vue+++ b/web/app/components/FirebaseAuth.vue@@ -1,11 +1,13 @@<script setup lang="ts">-import firebase from "firebase/compat/app";-import "firebase/compat/auth";import {+ getAuth,+ signInWithPopup,GoogleAuthProvider,GithubAuthProvider,- EmailAuthProvider,+ signInWithEmailAndPassword,+ createUserWithEmailAndPassword,} from "firebase/auth";+import { mdiGoogle, mdiGithub, mdiEmail } from "@mdi/js";const props = withDefaults(defineProps<{@@ -18,72 +20,182 @@ const router = useRouter();const authStore = useAuthStore();const notificationsStore = useNotificationsStore();const appStore = useAppStore();-const authContainer = ref<HTMLElement | null>(null);-const firebaseUIInitialized = ref(false);-let ui: any = null;-onMounted(async () => {- if (!import.meta.client) return;+const loading = ref(false);+const showEmailForm = ref(false);+const isSignUp = ref(false);+const email = ref("");+const password = ref("");+const emailError = ref("");- const firebaseui = await import("firebaseui");- await import("firebaseui/dist/firebaseui.css");+async function signInWithGoogle() {+ loading.value = true;+ try {+ const auth = getAuth();+ const result = await signInWithPopup(auth, new GoogleAuthProvider());+ onSuccess(result.user);+ } catch (error: unknown) {+ handleError(error);+ } finally {+ loading.value = false;+ }+}- // FirebaseUI requires the compat auth instance- const auth = firebase.auth();- ui = firebaseui.auth.AuthUI.getInstance() || new firebaseui.auth.AuthUI(auth);- ui.start("#firebaseui-auth-container", {- callbacks: {- signInSuccessWithAuthResult: (authResult: any) => {- notificationsStore.addNotification({- message: "Login successful!",- type: "success",- });- authStore.onAuthStateChanged(authResult.user);- router.push({ path: props.to });- return false;- },- uiShown: () => {- firebaseUIInitialized.value = true;- if (authContainer.value) {- Array.from(- authContainer.value.getElementsByClassName(- "firebaseui-idp-text-long",- ),- ).forEach((item: Element) => {- item.textContent =- item.textContent?.replace("Sign in with", "Continue with") ||- null;- });- }- },- },- signInFlow: "popup",- signInSuccessUrl: window.location.href,- signInOptions: [- GoogleAuthProvider.PROVIDER_ID,- GithubAuthProvider.PROVIDER_ID,- EmailAuthProvider.PROVIDER_ID,- ],- tosUrl: appStore.appData.url + "/terms-and-conditions",- privacyPolicyUrl: appStore.appData.url + "/privacy-policy",+async function signInWithGithub() {+ loading.value = true;+ try {+ const auth = getAuth();+ const result = await signInWithPopup(auth, new GithubAuthProvider());+ onSuccess(result.user);+ } catch (error: unknown) {+ handleError(error);+ } finally {+ loading.value = false;+ }+}++async function submitEmail() {+ emailError.value = "";+ loading.value = true;+ try {+ const auth = getAuth();+ let result;+ if (isSignUp.value) {+ result = await createUserWithEmailAndPassword(+ auth,+ email.value,+ password.value,+ );+ } else {+ result = await signInWithEmailAndPassword(+ auth,+ email.value,+ password.value,+ );+ }+ onSuccess(result.user);+ } catch (error: unknown) {+ handleError(error);+ } finally {+ loading.value = false;+ }+}++function onSuccess(user: unknown) {+ notificationsStore.addNotification({+ message: "Login successful!",+ type: "success",});-});+ authStore.onAuthStateChanged(user);+ router.push({ path: props.to });+}-onBeforeUnmount(() => {- if (ui) ui.delete();-});+function handleError(error: unknown) {+ const firebaseError = error as { code?: string; message?: string };+ const code = firebaseError.code || "";+ if (code === "auth/user-not-found" || code === "auth/invalid-credential") {+ emailError.value = "Invalid email or password";+ } else if (code === "auth/email-already-in-use") {+ emailError.value = "An account with this email already exists";+ } else if (code === "auth/weak-password") {+ emailError.value = "Password must be at least 6 characters";+ } else if (code === "auth/popup-closed-by-user") {+ // User closed popup, no error to show+ } else {+ emailError.value = firebaseError.message || "An error occurred";+ }+}</script><template>- <div>- <div id="firebaseui-auth-container" ref="authContainer" />- <v-progress-circular- v-if="!firebaseUIInitialized"- class="mx-auto d-block my-16"- :size="80"- :width="5"- color="primary"- indeterminate- />+ <div class="text-center">+ <v-btn+ block+ size="large"+ variant="outlined"+ class="mb-3"+ :loading="loading"+ @click="signInWithGoogle"+ >+ <v-icon :icon="mdiGoogle" class="mr-2" />+ Continue with Google+ </v-btn>++ <v-btn+ block+ size="large"+ variant="outlined"+ class="mb-3"+ :loading="loading"+ @click="signInWithGithub"+ >+ <v-icon :icon="mdiGithub" class="mr-2" />+ Continue with GitHub+ </v-btn>++ <v-btn+ v-if="!showEmailForm"+ block+ size="large"+ variant="outlined"+ class="mb-3"+ @click="showEmailForm = true"+ >+ <v-icon :icon="mdiEmail" class="mr-2" />+ Continue with Email+ </v-btn>++ <v-form v-if="showEmailForm" class="mt-4" @submit.prevent="submitEmail">+ <v-text-field+ v-model="email"+ label="Email"+ type="email"+ variant="outlined"+ density="comfortable"+ class="mb-2"+ required+ />+ <v-text-field+ v-model="password"+ label="Password"+ type="password"+ variant="outlined"+ density="comfortable"+ class="mb-2"+ required+ />+ <v-alert v-if="emailError" type="error" density="compact" class="mb-3">+ {{ emailError }}+ </v-alert>+ <v-btn+ block+ size="large"+ color="primary"+ type="submit"+ :loading="loading"+ >+ {{ isSignUp ? "Sign Up" : "Sign In" }}+ </v-btn>+ <v-btn+ block+ variant="text"+ size="small"+ class="mt-2"+ @click="isSignUp = !isSignUp"+ >+ {{+ isSignUp ? "Already have an account? Sign In" : "No account? Sign Up"+ }}+ </v-btn>+ </v-form>++ <p class="text-body-small text-medium-emphasis mt-4">+ By continuing, you agree to the+ <a :href="appStore.appData.url + '/terms-and-conditions'">+ Terms & Conditions+ </a>+ and+ <a :href="appStore.appData.url + '/privacy-policy'">Privacy Policy</a>+ </p></div></template>diff --git a/web/app/plugins/firebase.client.ts b/web/app/plugins/firebase.client.tsindex 86b4e827..04cdd8f0 100644--- a/web/app/plugins/firebase.client.ts+++ b/web/app/plugins/firebase.client.ts@@ -3,7 +3,7 @@ import type { FirebaseApp } from "firebase/app";import { getAuth, onAuthStateChanged } from "firebase/auth";import { useAuthStore } from "../stores/auth";-export default defineNuxtPlugin(async () => {+export default defineNuxtPlugin(() => {const config = useRuntimeConfig();const publicConfig = config.public as Record<string, string>;@@ -30,19 +30,6 @@ export default defineNuxtPlugin(async () => {getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];const auth = getAuth(app);- // Also initialize the compat SDK for FirebaseUI- if (import.meta.client) {- const firebase = (await import("firebase/compat/app")) as {- default: {- apps: unknown[];- initializeApp: (config: typeof firebaseConfig) => void;- };- };- if (!firebase.default.apps.length) {- firebase.default.initializeApp(firebaseConfig);- }- }-// Listen for auth state changes and update the auth storeconst authStore = useAuthStore();onAuthStateChanged(auth, (user) => {diff --git a/web/nuxt.config.ts b/web/nuxt.config.tsindex 1cf3a4b7..b12371dd 100644--- a/web/nuxt.config.ts+++ b/web/nuxt.config.ts@@ -30,9 +30,6 @@ export default defineNuxtConfig({"date-fns","firebase/app","firebase/auth",- "firebase/compat/app",- "firebase/compat/auth",- "firebaseui","libphonenumber-js","pusher-js","qrcode",@@ -51,14 +48,6 @@ export default defineNuxtConfig({icons: {defaultSet: "mdi-svg",},- display: {- thresholds: {- md: 960,- lg: 1280,- xl: 1920,- xxl: 2560,- },- },},},diff --git a/web/package.json b/web/package.jsonindex 7057a1c4..63f1bcda 100644--- a/web/package.json+++ b/web/package.json@@ -18,7 +18,6 @@"chartjs-adapter-moment": "^1.0.1","date-fns": "^4.3.0","firebase": "^12.13.0",- "firebaseui": "^6.1.0","flag-icons": "^7.5.0","libphonenumber-js": "^1.13.3","moment": "^2.30.1",diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yamlindex da825933..239df0fe 100644--- a/web/pnpm-lock.yaml+++ b/web/pnpm-lock.yaml@@ -25,9 +25,6 @@ importers:firebase:specifier: ^12.13.0version: 12.13.0- firebaseui:- specifier: ^6.1.0- version: 6.1.0([email protected])flag-icons:specifier: ^7.5.0version: 7.5.0@@ -3793,12 +3790,6 @@ packages:integrity: sha512-4CXDYRBGqN+57wVJkuXBYmpAVUSg3L6JAQa/DFqm238G73E1wuyc/JhGQJzN7vUf/CMphYau2zXbfWzDR5aTEw==,}- resolution:- {- integrity: sha512-j5yGMkP8T00UFgyO+78OxiN5vC5dzRQF3BEio+LhNvDbyfxWBsi3sfPArDm54VloaJwy2hm3erEiDWqHRC8rzw==,- }-resolution:{@@ -4124,14 +4115,6 @@ packages:integrity: sha512-iutR8ejvAqk6qUClnsPz3U3VIjTWp243AX4cD3iifak5t56to1J29xUIQgSDDzaAqKvhshZerzSahwMQj2TlvA==,}- resolution:- {- integrity: sha512-5WiVYVxPGMANuZKxg6KLyU1tyqIsbqf/59Zm4HrdFYwPtM5lxxB0THvgaIk4ix+hCgF0qmY89sKiktcifKzGIA==,- }- peerDependencies:- firebase: ^9.1.3 || ^10.0.0-resolution:{@@ -4741,13 +4724,6 @@ packages:integrity: sha512-pVKE4UdSQ7DvHzivsCIFx2BJn1mHG6KsyrFcaxFx6tONdneEuThrDx0Cj3AMg58KyN4pzYT+LHOotxDQDjNvkw==,}- resolution:- {- integrity: sha512-ao76b0bqSTKcEMt7Pui+J/S3eVF0b3GWfuKUwfe2lP5DKlLZOwBq37e0/bXEzxrw7/SuHAuYAdoCwY6mAYhrsg==,- }- engines: { node: ">=0.12.0" }-resolution:{@@ -9119,8 +9095,6 @@ snapshots:- [email protected]: {}-@@ -9380,12 +9354,6 @@ snapshots:transitivePeerDependencies:- "@react-native-async-storage/async-storage"- dependencies:- dialog-polyfill: 0.4.10- firebase: 12.13.0- material-design-lite: 1.3.0-@@ -9712,8 +9680,6 @@ snapshots:"@babel/types": 7.29.7source-map-js: 1.2.1- [email protected]: {}-