-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
66 lines (56 loc) · 2.02 KB
/
App.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
import React from "react";
import { Route, Switch } from "react-router-dom";
import { connect } from "react-redux";
import ProtectedRoute from "./components/ProtectedRoute";
import Home from "./components/Home";
import Login from "./components/Login";
import Verify from "./components/Verify";
import { doLogin } from "./actions";
import { myFirebase } from './firebase/firebase';
function App(props) {
const { isAuthenticated, isVerifying } = props;
console.log("Check");
if (myFirebase.auth().isSignInWithEmailLink(window.location.href)) {
var email = window.localStorage.getItem('emailForSignIn');
console.log(email);
if (!email) {
email = window.prompt('Please provide your email for confirmation');
}
// The client SDK will parse the code from the link for you.
myFirebase.auth().signInWithEmailLink(email, window.location.href)
.then(function(result) {
console.log("Success");
window.localStorage.removeItem('emailForSignIn');
doLogin(result.user);
// You can access the new user via result.user
// Additional user info profile not available via:
// result.additionalUserInfo.profile == null
// You can check if the user is new or existing:
// result.additionalUserInfo.isNewUser
}).catch(function(error) {
// Some error occurred, you can inspect the code: error.code
// Common errors could be invalid email and invalid or expired OTPs.
console.log(error);
});
}
return (
<Switch>
<ProtectedRoute
exact
path="/"
component={Home}
isAuthenticated={isAuthenticated}
isVerifying={isVerifying}
/>
<Route path="/login" component={Login} />
<Route path="/verify" component={Verify} />
</Switch>
);
}
function mapStateToProps(state) {
return {
isAuthenticated: state.auth.isAuthenticated,
isVerifying: state.auth.isVerifying
};
}
export default connect(mapStateToProps)(App);