-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase.ts
More file actions
75 lines (66 loc) · 2.69 KB
/
Copy pathfirebase.ts
File metadata and controls
75 lines (66 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { boot } from 'quasar/wrappers';
import { initializeApp } from 'firebase/app';
import firebaseConfig from '../assets/firebaseConfig';
import { connectAuthEmulator, EmailAuthProvider, getAuth, GoogleAuthProvider, UserCredential } from 'firebase/auth';
import { connectDatabaseEmulator, getDatabase, ref, set } from 'firebase/database';
import * as firebaseui from 'firebaseui';
import { User } from 'src/model/User';
const firebaseApp = initializeApp(firebaseConfig);
const firebaseAuth = getAuth(firebaseApp);
const firebaseDatabase = getDatabase(firebaseApp);
const googleProvider = new GoogleAuthProvider();
const emailProvider = new EmailAuthProvider();
if (location.hostname === 'localhost') {
// Point to the RTDB emulator running on localhost.
connectDatabaseEmulator(firebaseDatabase, 'localhost', 9001);
connectAuthEmulator(firebaseAuth, 'http://localhost:9099');
}
const uiConfig = {
signInSuccessUrl: '/#/success',
callbacks: {
signInSuccessWithAuthResult: function (authResult: UserCredential): boolean {
const user = {
uid: authResult.user.uid,
displayName: authResult.user.displayName,
email: authResult.user.email,
photoURL: authResult.user.photoURL,
} as User;
const dbRef = ref(firebaseDatabase, `users/${authResult.user.uid}`);
set(dbRef, user);
return true;
},
},
signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
googleProvider.providerId,
//firebase.auth.FacebookAuthProvider.PROVIDER_ID,
//firebase.auth.TwitterAuthProvider.PROVIDER_ID,
//firebase.auth.GithubAuthProvider.PROVIDER_ID,
emailProvider.providerId,
//firebase.auth.PhoneAuthProvider.PROVIDER_ID,
//firebaseui.auth.AnonymousAuthProvider.PROVIDER_ID
],
// tosUrl and privacyPolicyUrl accept either url string or a callback
// function.
// Terms of service url/callback.
tosUrl: '<your-tos-url>',
// Privacy policy url/callback.
privacyPolicyUrl: function () {
window.location.assign('<your-privacy-policy-url>');
},
};
// Initialize the FirebaseUI Widget using Firebase.
const ui = new firebaseui.auth.AuthUI(firebaseAuth);
// "async" is optional;
// more info on params: https://v2.quasar.dev/quasar-cli/boot-files
export default boot(async ({ app }) => {
// Import the functions you need from the SDKs you need
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Initialize Firebase
app.config.globalProperties.$firebase = firebaseApp;
});
function mountSignIn() {
ui.start('#firebaseui-auth-container', uiConfig);
}
export { firebaseApp, firebaseAuth, firebaseDatabase, mountSignIn };