とりあえず説明しやすいように作成中コード貼ります。
js
1class Login extends Component{ 2 constructor (props) { 3 super(props) 4 this.state = { 5 email: '', 6 password:'' 7 }; 8 } 9 10 componentWillMount() { 11 firebase.initializeApp() 12 }; 13 14 handleChange_email = (event) => { 15 this.setState({ 16 email: event.target.value, 17 }); 18 }; 19 20 handleChange_password = (event) => { 21 this.setState({ 22 password: event.target.value 23 }); 24 }; 25 26 handleChange_button = (event) => { 27 firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password) 28 }; 29 30componentDidMount(){ 31 firebase.auth().onAuthStateChanged(function(user){ 32 if(user){ 33 34 } 35 else { 36 37 } 38 }) 39}; 40 41 render(){ 42 return( 43 <div> 44 <TextField 45 id="emailform" 46 value={this.state.email} 47 floatingLabelText="UserID" 48 onChange={this.handleChange_email} 49 style={{ 50 margin: '0 auto', 51 }} 52 /> 53 <br /> 54 <TextField 55 id="passwordform" 56 value={this.state.password} 57 floatingLabelText="password" 58 type='password' 59 onChange={this.handleChange_password} 60 /> 61 <br /> 62 <RaisedButton 63 label="Login" 64 sedondary={true} 65 onClick={this.handleChange_button} 66 /> 67 </div> 68 ) 69 } 70}
まだif(user)は未完成何ですけど、とりあえず、このコードのやりたいことは、
このページ来た時に、発動する
componentWillMount() {
firebase.initializeApp()
};
こやつでfirebaseのアプリ起動して、
ボタン押した時に、
componentDidMount(){
firebase.auth().onAuthStateChanged(function(user){
if(user){
} else { }
})
};
こやつでログイン状態参照して、(<Route>で記述した別ページに飛ばそうとしてます。)←ここは方針立たず。
とりあえずcomponentWillMount() と componentDidMount() ってこういう認識で合ってる???
っていうのと、<Route>で示したページにif(user)のとこで飛ばす処理を知りたいです。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。