In order to connect your application to the Firebase authentication API, you should start by creating a Firebase application instance:
let config = { apiKey: 'YourAPIKey', databaseURL: 'YourDBURL', authDomain: 'YourAuthDomain' } let app = firebase.initializeApp(config)
You can find the necessary keys and URLs in the popup that opens if you click on the Web Setup button:
Now you can use the app instance to access the auth()
object and its methods. Check out the official Firebase documentation regarding the authentication API: https://firebase.google.com/docs/auth/users.
The most important part of the API for us is the methods to create and sign in a user, and the method that listens to the changes in the authentication state:
app.auth().createUserWithEmailAndPassword(email, password)
Or:
app.auth().signInWithEmailAndPassword(email, password)