1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Firebase tips(Email Auth:javascript)

Last updated at Posted at 2017-09-19

FIREBASE TIPS

1. Connect and Create Email User

create
<script src="https://www.gstatic.com/firebasejs/4.1.1/firebase.js"></script>
<script>
  var config = {
    apiKey: 'XXXXXXXXX',
    authDomain: 'XXXXXXX.firebaseapp.com',
    databaseURL: 'https://XXXXXXXX.firebaseio.com/',
    storageBucket: 'XXXXXX.appspot.com',
    messagingSenderId: 'XXXXXXXX',
  };
  firebase.initializeApp(config);
   
  firebase.auth().createUserWithEmailAndPassword('YYYYYYY@XXXXX.com', 'XXXXXXX').catch((error) => {
      console.log('code:' + error.code + 'message' + error.message);
  });
</script>

result
email_auth_create.png

2. Login with Email and Password.

login
    firebase.initializeApp(config);
    firebase.auth().signInWithEmailAndPassword('coffeeandcode.tokyo@gmail.com', 'coffee').catch((error) => {
        console.log('code:' + error.code + 'message' + error.message);
    });
    firebase.auth().onAuthStateChanged((user) => {
        if (user) {
            console.log('login success');
        }else{}

    });

result
signin.png

3. Logout

logout
    firebase.auth().signOut().then( () => {
        console.log('logout sucess');
    }).catch(function (error) {
        console.log('code:' + error.code + 'message' + error.message);
    });

result
signout.png

4. Email Verfication

verfication
    firebase.initializeApp(config);
    firebase.auth().createUserWithEmailAndPassword('coffeeandcode.tokyo@gmail.com', 'coffee').catch((error) => {
        console.log('code:' + error.code + 'message' + error.message);
    });
    firebase.auth().onAuthStateChanged(function (user) {
        if (user) {
            if (user.emailVerified == false) {
                user.sendEmailVerification().then(() => {
                    console.log('sent email');
                }, (error) => {
                    console.log('code:' + error.code + 'message' + error.message);
                });
            }
        } else { }

    });

result1
email1.png

result2
email2.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?