-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-v8.js
83 lines (73 loc) · 2.3 KB
/
app-v8.js
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
76
77
78
79
80
81
82
83
import logo from './logo.svg';
import './App.css';
import { auth, firedb, fireui } from './firebase';
import firebase from "firebase";
import React, { useEffect } from 'react';
function App() {
useEffect(() => {
const uiConfig = {
signInSuccessUrl: 'http://localhost:port_number/',
autoUpgradeAnonymousUsers: true,
signInFlow: 'popup',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID
],
callbacks: {
signInFailure: function (error) {
// Temp variable to hold the anonymous user data if needed.
let data = null;
// Hold a reference to the anonymous current user.
let anonymousUser = firebase.auth().currentUser;
// For merge conflicts, the error.code will be
// 'firebaseui/anonymous-upgrade-merge-conflict'.
if (error.code != 'firebaseui/anonymous-upgrade-merge-conflict') {
return Promise.resolve();
}
console.log("I'm here.")
// The credential the user tried to sign in with.
var cred = error.credential;
// Copy data from anonymous user to permanent user and delete anonymous
// user.
// ...
// Finish sign-in after data is copied.
return firebase
.auth()
.signInWithCredential(cred)
.then(anonymousUser.delete())
}
}
};
if (fireui.auth.AuthUI.getInstance()) {
const ui = fireui.auth.AuthUI.getInstance()
ui.start('#firebaseui-auth-container', uiConfig)
}
else {
const ui = new fireui.auth.AuthUI(firebase.auth())
ui.start('#firebaseui-auth-container', uiConfig)
}
firebase.auth().onAuthStateChanged((user) => {
if (user) {
console.log(user.uid);
}
else {
console.log('User is signed out')
}
})
}, [])
const signInAnonymously = async (e) => {
auth.signInAnonymously();
}
const signOutGoogle = async (e) => {
auth.signOut();
}
return (
<div className="App">
<div id='firebaseui-auth-container'>
</div>
<button onClick={signInAnonymously}>Sign-In Anonymously</button>
<button onClick={signOutGoogle}>Sign out</button>
</div>
);
}
export default App;