# Login via Firebase

## Login API with Firebase Token&#x20;

The Login API with Firebase Token Conversion enables users to log in to the e-commerce application using their Firebase authentication token. This API securely converts the Firebase token into a bearer token, providing users with authorized access to the app's resources. Additionally, the API guides new users to either register or proceed to the home screen based on their authentication status.

<figure><img src="https://3686328336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd1Iq7THDAagTQzeC9rTN%2Fuploads%2F9eRcdHNV47BPVgmgxgBy%2Fimage.png?alt=media&#x26;token=c58cbc7a-3668-43eb-bfd6-218294ebae18" alt=""><figcaption><p><strong>After this page app lead user to home page if user is registered</strong></p></figcaption></figure>

### Endpoint

* `{{baseurl}}/api/v1/login`

### Method

* POST

### Request Parameters

* None&#x20;

### **Request Body:**

```json
{
  "firebase_token": "tocken_examble"
   "country_id": "country_examble"
    "lang_id": "language_examble"
}
```

### Response Format

* The API responds with a JSON object containing the converted bearer token and additional user-related information upon successful login.

```json
For registred user
{
    "status": true,
    "message": "User details",
    "data": {
        "user": {
            "id": 80,
            "name": "shiju s",
            "phone": "+912222233333",
            "email": "shi@gmail.com",
            "avatar": null,
            "is_guest": null,
            "status": 1,
            "firebase_id": 76,
            "default_shipping_address": null,
            "default_billing_address": null,
            "country_id": 0,
            "lang_id": 0,
            "remember_token": null,
            "created_at": "2023-07-18T10:40:30.000000Z",
            "updated_at": "2023-08-04T07:36:35.000000Z",
            "deleted_at": null,
            "email_verified": 0,
            "email_token": 346992,
            "email_token_expire_at": "2023-08-04 13:15:23",
            "email_verified_at": "2023-07-29 12:27:08",
            "bearer_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiZTRhMzNjMjA4OGY1NzI0ZmFiYjk4Njk1YTEzYWViYzhlYzg5YWYzZTBjN2YwYTdkMDkzMTM5ZGJiZTliOGZiZWU0NzFkNGY5OTZmZDI1YzQiLCJpYXQiOjE2OTExMzQ1OTUuNjYyMDY3LCJuYmYiOjE2OTExMzQ1OTUuNjYyMDcsImV4cCI6MTcyMjc1Njk5NS42NjAwMzQsInN1YiI6IjgwIiwic2NvcGVzIjpbXX0.JbeUpH3HwzgDnQsYY7ff8NEfVYCWJU7gDecpFNrv7NhWxNyXlHUKCKvePdwiuHztek7Rel-boT6nrIaBYONqStjxQr6rxuRjdN9wUCUYRAupaEOTY9TX_ZHVOK8MBg2NrdngKkaC-RXxsxsy6O7A0T3g4F8l2uCxD6YA09rm8t-oIpyR1Clv092d4mOIzMEpjKE5MxpQnPB0u4f9eSBzH-wRJWAA685xMsJtUm3hYMu9P3wBnaeA1zAYpGbF23RHl_NyCvPHhf_JVec9JG9uQFSfykRxc1EGxORwPthq8R3sDe_aArNsLyzYFRNEG_tsbg-AA784h4_IBYoM-hwankV4I6BT41uOwUHYRXgBj0lmhh0Jn5z1G7MCaU7fMer2HMlCkNrEibr6Gnkh0hYyuUz1uF-f_WtRRLO29NNNbAydWUGsWRxgNLdXApy9rQdQ4_kGq3TUYJJy31_WHdYJAXHX_97-aQL51ubL3RbnK-FfdHeRzP5ICiVA7feu5jsgrs7S-aoTu4plJlx5IPwk3yXV1Bf1qhaEQLO-yrbDoiZTW3pmIUyxgWGTCwf3HwTRcqHQMT9M95zt6zFP3-CUcDWFNMsJSurS4EDs2bIxRl6KQU8Q3Dl07OX6SK_iDtgp2Twu29jbS422m2wnkaDjxMIUwYjYiHXY4JEidl30rwk"
        }
    }
}

For new user

{
    "status": true,
    "message": "User details",
    "data": {
        "user": {
            "id": 87,
            "name": null,
            "phone": "+919946210988",
            "email": null,
            "avatar": null,
            "is_guest": null,
            "status": 1,
            "firebase_id": 83,
            "default_shipping_address": null,
            "default_billing_address": null,
            "country_id": 0,
            "lang_id": 0,
            "remember_token": null,
            "created_at": "2023-07-27T05:13:29.000000Z",
            "updated_at": "2023-08-04T09:24:40.000000Z",
            "deleted_at": null,
            "email_verified": 0,
            "email_token": null,
            "email_token_expire_at": null,
            "email_verified_at": null,
            "bearer_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiOWRjYmU5Y2Q2YTZjOWNjOWRhNTcwZGNhNDFkNmI5ZWViNDhmYjVmNzNjZjEzOWViZGI3YjY1MjA2ZThiNzExZDJhZDljNDM4NGM0YjM5NTAiLCJpYXQiOjE2OTExNDEwODAuMjEyODQ2LCJuYmYiOjE2OTExNDEwODAuMjEyODQ5LCJleHAiOjE3MjI3NjM0ODAuMjEwMjM5LCJzdWIiOiI4NyIsInNjb3BlcyI6W119.Z68SWaRR-AAsM8GH1r8VZx0h8kBPS7D0PApxE7FICCXi8t5-XyL2HTxHIRoPCTBs367D1i2rVfHOIhxcY1neUP9gOTUt9Nl4EbrAroyn3vIblf1iYp-wGnzSl6mSlEeJanjAS6qJuHSNVjHfqhh8GEvwWbuiXhuDHwQ4dGDEKt479cJCu4budN_DM124JmdN5PvzDcoO4OqPjKla3yIOiv7JmBTWwBTgre8WeeBQ-YnxyPSjrSO2i5LmyoGaoli5aZhejclMT-bv8u5Oef-o-rgb1oulzwpf-8gWa-LVAP4DhM4F862X1H6-fwo90q9wl4nBKGdGIgcDI65iVZfDrPZ6GkMz-04ACy7MtD--iA6GdMx52x31HNTd6kA7u0NmuEj-LKFMvQhnWSQuTAaXp4IhPeI2GThAckSpjxD9tO3lS2aXEwVQynOz88hUIh-lRPrGECYL1cFHwvx8O7HkRkCKIiIjuI-OqKL6DRAJdcSVwYBUJk33gKI6EkZxG5KgHZLBrZTFH3MPhBOyysTRhqmqHZgBvzlrDqqc2XO8AVopKg_X2Ik4wy5eaWBit8qN5YJHXeDtrJtOk0t5Mxrf9CHigMbQQfOJVv22OH4P6-VY_Je3UgFytkmc6uW2KnmMKAMu6F1iB2lvUaSZEhoH47URmONDS5uTQpq9zsFcfHU"
        }
    }
}

```

### Features

* **Token Conversion**: The API converts the user's Firebase token into a bearer token, which serves as an access token for authorized interactions with the app's backend resources.
* **Secure Authentication**: The Firebase token conversion process ensures secure and validated user authentication, protecting sensitive user data.
* **User Guidance**: The API assesses the user's authentication status and guides new users to the appropriate action, either directing them to the registration process or granting access to the home screen for existing users.

### Usage

The Login API with Firebase Token Conversion is used when users attempt to log in to the e-commerce application. When users provide their Firebase authentication token, the API validates the token's authenticity and converts it into a bearer token, signifying the user's authorized access to the app's backend.

### Best Practices

* **Firebase Token Validation**: Ensure that the Firebase token is valid and not expired before initiating the conversion process.
* **Bearer Token Security**: Implement secure practices for handling bearer tokens, such as setting expiration times and using HTTPS for all communication.
* **User Guidance Logic**: Implement robust logic to guide new users to register and existing users to proceed to the home screen based on their authentication status.
