Understanding Firebase services

Do you know Firebase? Firebase is a mobile platform that helps you quickly develop high-quality apps, grow your user base, and earn more money. Firebase is made up of complementary features that you can mix-and-match to fit your needs. I am finding Firebase very interesting, especially when it’s time to add some features to games. Today I will show you a brief overview of the service, showing you how to make the simplest user authentication ever: an anonymous authentication. Don’t be scared about anonymous authentication if you plan to fidelize your players as Firebase allows you to turn anonymous users into registered users at any time. So let’s get started with your first project, navigate to the console and click on “CREATE NEW PROJECT” Name your project, enter your location and click on “CREATE PROJECT” Today we are creating a web app, so select “Add Firebase to your web app” Once in the app dashboard, select “Auth” then “SET UP SIGN IN METHOD”. You will see all authentications methods are disabled, and we’ll enable “Anonymous” Enable it and save Your authentication now should be enabled. That’s what we are going to do now: you can authenticate and get an unique id which will remain the same even if you reload the page.
Signing out will delete your authentication unique id. Remember it’s an anonymous authentication. Look at the code:
<html&gt;
<head&gt;

<script src="https://code.jquery.com/jquery-1.12.4.min.js"&gt;</script&gt;
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"&gt;</script&gt;
<script&gt;

     $(document).ready(function(){
          var config = {
               apiKey: "AIzaSyD4NczHDYCUHIeX8X-ZXxErwQZvdTLiflA",
               authDomain: "test-c2cc1.firebaseapp.com",
               databaseURL: "https://test-c2cc1.firebaseio.com",
               storageBucket: "test-c2cc1.appspot.com",
          };
          
          firebase.initializeApp(config);
          
          firebase.auth().onAuthStateChanged(function(user){
               if(user){
                    var uid = user.uid
                    $("#message").html('user authenticated with uid ' + uid + ' - <a id = "signout" href = "#"&gt;sign out</a&gt;')
               }
               else{
                    $("#message").html('user not authenticated - <a id = "authenticate" href = "#"&gt;authenticate</a&gt;');
               }
          
          })
          
          $(document).on("click", "#authenticate", function(){
               firebase.auth().signInAnonymously();                    
          });
          
          $(document).on("click", "#signout", function(){
               firebase.auth().signOut();                    
          })
                    
     });

</script&gt;
    
</head&gt;
<body&gt;
     <div id = "message" style = "font: normal 20px Helvetica"&gt;</div&gt; 
</body&gt;
</html&gt; 

Everything is inside these four methods: firebase.initializeApp(config);: creates and intializes a Firebase app. config is an object with configuration options. firebase.auth().signInAnonymously();: asynchronously signs in as an anonymous user. If there is already an anonymous user signed in, that user will be returned; otherwise, a new anonymous user identity will be created and returned. firebase.auth().signOut();: signs out the current user. firebase.auth().onAuthStateChanged(callback);: adds a listener for auth state changes and executes callback function. That’s all at the moment, next time I will show you how to integrate this features and more features in your games.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers