enter.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <div class="flex flex-col items-center justify-center min-h-screen">
  3. <SmartSpinner v-if="signingInWithEmail" />
  4. <SmartLoadingIndicator v-else />
  5. <pre v-if="error">{{ error }}</pre>
  6. </div>
  7. </template>
  8. <script lang="ts">
  9. import { defineComponent } from "@nuxtjs/composition-api"
  10. import { initializeFirebase } from "~/helpers/fb"
  11. import { isSignInWithEmailLink, signInWithEmailLink } from "~/helpers/fb/auth"
  12. import { getLocalConfig, removeLocalConfig } from "~/newstore/localpersistence"
  13. export default defineComponent({
  14. layout: "empty",
  15. data() {
  16. return {
  17. signingInWithEmail: false,
  18. error: null,
  19. }
  20. },
  21. beforeMount() {
  22. initializeFirebase()
  23. },
  24. async mounted() {
  25. if (isSignInWithEmailLink(window.location.href)) {
  26. this.signingInWithEmail = true
  27. let email = getLocalConfig("emailForSignIn")
  28. if (!email) {
  29. email = window.prompt(
  30. "Please provide your email for confirmation"
  31. ) as string
  32. }
  33. await signInWithEmailLink(email, window.location.href)
  34. .then(() => {
  35. removeLocalConfig("emailForSignIn")
  36. this.$router.push({ path: "/" })
  37. })
  38. .catch((e) => {
  39. this.signingInWithEmail = false
  40. this.error = e.message
  41. })
  42. .finally(() => {
  43. this.signingInWithEmail = false
  44. })
  45. }
  46. },
  47. })
  48. </script>