|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div id="firebaseui-auth-container" ref="authContainer"></div> |
| 4 | + <v-progress-circular |
| 5 | + v-if="!firebaseUIInitialized" |
| 6 | + class="mx-auto d-block my-16" |
| 7 | + :size="80" |
| 8 | + :width="5" |
| 9 | + color="primary" |
| 10 | + indeterminate |
| 11 | + ></v-progress-circular> |
| 12 | + </div> |
| 13 | +</template> |
| 14 | + |
| 15 | +<script lang="ts"> |
| 16 | +import { Vue, Component } from 'vue-property-decorator' |
| 17 | +import { ProviderId } from 'firebase/auth' |
| 18 | +import { auth } from 'firebaseui' |
| 19 | +import { NotificationRequest } from '~/store' |
| 20 | +
|
| 21 | +@Component |
| 22 | +export default class FirebaseAuth extends Vue { |
| 23 | + ui: auth.AuthUI | null = null |
| 24 | + firebaseUIInitialized = false |
| 25 | +
|
| 26 | + beforeDestroy(): void { |
| 27 | + if (this.ui) { |
| 28 | + this.ui.delete() |
| 29 | + } |
| 30 | + } |
| 31 | +
|
| 32 | + mounted(): void { |
| 33 | + if (process.browser) { |
| 34 | + const firebaseui = require('firebaseui') |
| 35 | + require('firebaseui/dist/firebaseui.css') |
| 36 | + this.ui = new firebaseui.auth.AuthUI(this.$fire.auth) |
| 37 | + this.ui?.start('#firebaseui-auth-container', this.uiConfig()) |
| 38 | + } |
| 39 | + } |
| 40 | +
|
| 41 | + uiConfig(): any { |
| 42 | + return { |
| 43 | + callbacks: { |
| 44 | + signInSuccessWithAuthResult: () => { |
| 45 | + this.$store.dispatch('addNotification', { |
| 46 | + message: 'Login successfull!', |
| 47 | + type: 'success', |
| 48 | + } as NotificationRequest) |
| 49 | + this.$router.push({ name: 'index' }) |
| 50 | + return false |
| 51 | + }, |
| 52 | + uiShown: () => { |
| 53 | + // The widget is rendered. |
| 54 | + // Hide the loader. |
| 55 | + this.firebaseUIInitialized = true |
| 56 | + const container = this.$refs.authContainer as HTMLElement |
| 57 | + Array.from( |
| 58 | + container.getElementsByClassName('firebaseui-idp-text-long') |
| 59 | + ).forEach((item: Element) => { |
| 60 | + item.textContent = |
| 61 | + item.textContent?.replace('Sign in with', 'Continue with') || null |
| 62 | + }) |
| 63 | + }, |
| 64 | + }, |
| 65 | + // Will use popup for IDP Providers sign-in flow instead of the default, redirect. |
| 66 | + signInFlow: 'popup', |
| 67 | + signInSuccessUrl: this.$store.getters.getAppData.url, |
| 68 | + signInOptions: [ |
| 69 | + // Leave the lines as is for the providers you want to offer your users. |
| 70 | + ProviderId.GOOGLE, |
| 71 | + ProviderId.GITHUB, |
| 72 | + ProviderId.PASSWORD, |
| 73 | + ], |
| 74 | + // Terms of service url. |
| 75 | + tosUrl: this.$store.getters.getAppData.url + '/terms-and-conditions', |
| 76 | + // Privacy policy url. |
| 77 | + privacyPolicyUrl: this.$store.getters.getAppData.url + '/privacy-policy', |
| 78 | + } |
| 79 | + } |
| 80 | +} |
| 81 | +</script> |
0 commit comments