# Set up your own auth URL

## Step 1: Creating Firebase Project

Create your own Firebase Project on: <https://console.firebase.google.com/>

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FzaiREIklRjLYQLqIEmWR%2F01.png?alt=media&#x26;token=b5692e84-12e7-4295-b776-0545816a6429" alt=""><figcaption></figcaption></figure>

## Step 2: Setting up Authentication

Add *"Authentication"* to your Project:

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FS9HAn2YeCsZ0Y2u5YAUr%2F01.png?alt=media&#x26;token=6d469c5f-dd4b-453b-9bfc-a72b96929d76" alt=""><figcaption></figcaption></figure>

Add *"Anonymous"* (to retrieve pairing code) and at least one other sign-in method. We suggest *"Email/Password"* and *"Google"* sign in (as they don't need any extra step):

<div><figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FM4VXTPAI4b8aXxK7c8q3%2F02.png?alt=media&#x26;token=cf625c3e-fe15-4e7f-a22a-7132c82606f1" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FJnylR4ikF1Z0YTRpep8v%2F03.png?alt=media&#x26;token=faf17a8d-d518-41c3-b71b-39432b00823a" alt=""><figcaption></figcaption></figure></div>

## Step 3: Setting up Realtime Database

Add *"Realtime Database"* to your Project:

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FS0i1fR9JStTIeAly8FXq%2F01.png?alt=media&#x26;token=1933bacb-0ebc-4d5e-bc84-6ca12c96d502" alt=""><figcaption></figcaption></figure>

Select Database Location and any security rule (we will change this in next step):

<div><figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FXNhw7E2xRKxO5A3d3iAw%2F02.png?alt=media&#x26;token=ecc97efb-110d-4f87-ae09-10839946d6b2" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2F7LmQUfIusJ7xlZ4fTFct%2F03.png?alt=media&#x26;token=1747a1c1-26e3-443b-b568-421cb47092a0" alt=""><figcaption></figcaption></figure></div>

Now switch to the *"Rules"* tab, paste the code below and click *"Publish"* (these rules ensure that users can only read/write their own data):

```
{
  "rules": {
    "users": {
    	"$user_id": {        
        ".write": "auth.uid == $user_id",
        ".read": "auth.uid == $user_id"
    	}
  	},
    "tokens": {
      ".write": "auth.token.email != null",
      "$code": { 
        ".write": "auth.uid.toLowerCase().beginsWith($code)",
        ".read": "auth.uid.toLowerCase().beginsWith($code)",
      }
    }
  }
}
```

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FTBq83CoZ78HtMUc8I8ou%2F04.png?alt=media&#x26;token=abbdf0db-6545-4646-8da5-f421d0029ecf" alt=""><figcaption></figcaption></figure>

## Step 4: Host your Auth Page

Add *"Hosting"* to your Project:

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FiYrPRDrCvyum9MoWZ2MJ%2F01.png?alt=media&#x26;token=bf852b8c-1f33-4233-b849-c9997fdaf6c5" alt=""><figcaption></figcaption></figure>

Following the steps below to set up Firebase Hosting:

<div><figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FHocvobPBxV8w9vvFSWBw%2F02.png?alt=media&#x26;token=57ee7de8-b750-444f-a1fd-65a6a2998b36" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FpAGV5I0Gw6dKiyLLMWCM%2F03.png?alt=media&#x26;token=cdada3ac-983a-4500-a054-5c848d65871f" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2F41WYu77DpjKwiuKr87g0%2F04.png?alt=media&#x26;token=1da946ef-e088-418a-9da1-724d9197e5b3" alt=""><figcaption></figcaption></figure></div>

Afterwards copy the *"index.html"* which is delivered with the AuthPair Unity package (in Web folder) to the currently created *"public"* folder:

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2F7XBQZJtFKbWDacrpX2oI%2F05.png?alt=media&#x26;token=3a460ece-b66b-4bb6-b02e-77ff1edc31e7" alt=""><figcaption></figcaption></figure>

... and run `firebase deploy` in your command line to deploy the new index file.

Then you should find your own auth page on `https://[YOUR_PROJECT_ID].web.app`

<div><figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2F4dNRAjsvNpCqMMlxJBs2%2F06.png?alt=media&#x26;token=c8863fc1-7201-476a-ad82-82859fe8493b" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FqQT7vZFFIH0R4mQzriJI%2F07.png?alt=media&#x26;token=fb105020-2821-4559-9cd1-6478d63a018f" alt=""><figcaption></figcaption></figure></div>

## Step 5: Link to your new Firebase Project

Finally open the AuthPair Demo scene in Unity or add the AuthPair prefab to your scene as described in [get-started](https://appscore.gitbook.io/authpair/how-to/get-started "mention")

Then copy the *"Realtime Database"* path and the *"API Key"* (from Firebase Project Settings) into the [firebase-auth-script](https://appscore.gitbook.io/authpair/components/firebase-auth-script "mention") (Settings in AuthPair prefab) as shown on the Screenshot below:

<div><figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FXMm7aFiSA88oV430VFBU%2FFirebase%20Auth%20Component%20-%20Find.png?alt=media&#x26;token=e01444f2-85ad-410c-b579-702f22e31b22" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2Fp8u1MSTIuUybK4i3r16m%2FFirebase%20Auth%20Component%20-%20Change%20URL.png?alt=media&#x26;token=0a7dc9e7-8c26-4a14-b740-d8cdd53a3d06" alt=""><figcaption></figcaption></figure> <figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FcQJ3pCsdmpos9DImtqhW%2FFirebase%20Auth%20Component%20-%20Change%20Key.png?alt=media&#x26;token=0b13ed63-1526-43be-9326-1e1cb57ee964" alt=""><figcaption></figcaption></figure></div>

And change the URL of the *"AuthInstruction"* text to your own auth page: `https://[YOUR_PROJECT_ID].web.app`

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2Fc2RblhHvReX5ICyoJyoi%2FAuthPair%20Instructions.png?alt=media&#x26;token=2e254403-9a0b-49bd-aa73-c41b7afc4aef" alt=""><figcaption></figcaption></figure>

## The Result

Now run your Unity scene, klick *"Sign In",* enter the shown pairing code on your newly created auth page and click *"Connect Device"*.

You'll see that your Unity scene automatically logs in and the moving game objects are updating your Firebase Realtime Database every second:

<figure><img src="https://1206787428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwlvUby0Vre29AiwkM9h5%2Fuploads%2FwI6UjwYGwjoJqzfHHZDk%2FUpdating%20DB.png?alt=media&#x26;token=84446bd4-c6e9-44fc-bdda-1fd3b98f9b66" alt=""><figcaption><p>Game Objects and Texts are updating the Firebase Realtime Database</p></figcaption></figure>

If you stop and run the scene again, the objects and score will continue with the previous position and score since those values were saved in the database.

### Device Independent Storage

Because the object data (position, rotation, scale) and the text value is stored in the user account and not on the device, you now have a Device Independent Storage.

**That means, even if you run the app/game on another device you still have the same data** :tada:
