Skip to content

Commit 3dd3b18

Browse files
author
badripaudel77
committed
config related firebase variables migrated to environment files. gitignore file updated.
1 parent a4ac072 commit 3dd3b18

8 files changed

+51
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ yarn-error.log
2828
!.vscode/extensions.json
2929
.history/*
3030

31+
#env variables
32+
src/environments/*
33+
3134
# Miscellaneous
3235
/.angular/cache
3336
.sass-cache/

src/app/app.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, isDevMode, OnInit} from '@angular/core';
22
import {AuthenticationService} from "./services/authentication.service";
33

44
@Component({
@@ -11,6 +11,12 @@ export class AppComponent implements OnInit{
1111

1212
}
1313
ngOnInit(): void {
14+
if(isDevMode()){
15+
console.info("[** App is running in development mode **]");
16+
}
17+
else {
18+
console.info("[** App is running in production mode **]");
19+
}
1420
this.authenticationService.detectAutoLogin();
1521
}
1622

src/app/constants/app.constants.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/**
2-
* Firebase Database REST API
3-
* Using firebase endpoints https://firebase.google.com/docs/reference/rest/database
2+
* Define app constants here if needed.
43
*/
54
const APP_CONSTANTS = {
6-
FIREBASE_BASE_URL : 'https://ng-app-e6a4b-default-rtdb.firebaseio.com'
5+
// TODO : TO be added if any ...
76
}
87

9-
export { APP_CONSTANTS };
8+
export { APP_CONSTANTS };

src/app/services/authentication.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {APP_CONSTANTS} from "../constants/app.constants";
21
import {Injectable} from "@angular/core";
32
import {HttpClient, HttpErrorResponse, HttpParams} from "@angular/common/http";
43
import {Observable, catchError, throwError, Subject, BehaviorSubject} from "rxjs";
@@ -7,6 +6,7 @@ import {NgForm} from "@angular/forms";
76
import {AuthResponseDataModel} from "../models/auth-response-data.model";
87
import {CustomerUserModel} from "../models/customer-user.model";
98
import {Router} from "@angular/router";
9+
import {environment} from "../../environments/environment";
1010

1111
/**
1212
* Firebase Authentication
@@ -16,9 +16,11 @@ import {Router} from "@angular/router";
1616
providedIn: 'root'
1717
})
1818
export class AuthenticationService {
19-
FIREBASE_SIGNUP_URL = APP_CONSTANTS.FIREBASE_SIGNUP_URL;
20-
FIREBASE_SIGNIN_URL = APP_CONSTANTS.FIREBASE_SIGNIN_URL;
21-
FIREBASE_AUTH_API_KEY = APP_CONSTANTS.FIREBASE_AUTH_API_KEY;
19+
APP_CONSTANTS = environment;
20+
21+
FIREBASE_SIGNUP_URL = this.APP_CONSTANTS.FIREBASE_SIGNUP_URL;
22+
FIREBASE_SIGNIN_URL = this.APP_CONSTANTS.FIREBASE_SIGNIN_URL;
23+
FIREBASE_AUTH_API_KEY = this.APP_CONSTANTS.FIREBASE_AUTH_API_KEY;
2224

2325
//userSubject = new Subject<CustomerUserModel>(); // we can emit this when we login or logout etc.
2426

src/app/services/recipe.service.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Injectable} from "@angular/core";
22
import RecipeModel from "../recipes/models/Recipe.model";
3-
import {exhaustMap, Subject, take} from "rxjs";
4-
import {HttpClient, HttpHeaderResponse, HttpParams} from "@angular/common/http";
5-
import {APP_CONSTANTS} from "../constants/app.constants";
6-
import {AuthenticationService} from "./authentication.service";
3+
import { Subject } from "rxjs";
4+
import { HttpClient } from "@angular/common/http";
5+
import { AuthenticationService } from "./authentication.service";
6+
import { environment } from "../../environments/environment";
77

88
@Injectable({
99
providedIn: 'root'
@@ -13,6 +13,7 @@ export class RecipeService {
1313

1414
// recipeSelected = new Subject<RecipeModel>();
1515
recipesChanged = new Subject<RecipeModel[]>();
16+
APP_CONSTANTS = environment;
1617

1718
constructor(private http: HttpClient, private authenticationService: AuthenticationService) {
1819
}
@@ -58,7 +59,7 @@ export class RecipeService {
5859
*/
5960
saveRecipes() {
6061
let allRecipes: RecipeModel[] = this.getRecipes();
61-
return this.http.put<RecipeModel>(`${APP_CONSTANTS.FIREBASE_BASE_URL}/recipes.json`, allRecipes);
62+
return this.http.put<RecipeModel>(`${this.APP_CONSTANTS.FIREBASE_BASE_URL}/recipes.json`, allRecipes);
6263
}
6364

6465
fetchDataFromServer() {
@@ -68,17 +69,18 @@ export class RecipeService {
6869
* and unsubscribe as it is needed only time. Same as unsubscribing immediately
6970
* exhaustMap() waits for the first observable to complete
7071
* We can also use interceptors to send headers.
72+
* Higher order mapping : https://blog.angular-university.io/rxjs-higher-order-mapping/
7173
*/
7274

7375
// one observable inside of another, as we have to wait few time to complete and user in needed in another observable.
7476
this.authenticationService.userSubject.subscribe((user) => {
75-
this.http.get<RecipeModel[]>(`${APP_CONSTANTS.FIREBASE_BASE_URL}/recipes.json`)
77+
this.http.get<RecipeModel[]>(`${this.APP_CONSTANTS.FIREBASE_BASE_URL}/recipes.json`)
7678
.subscribe((data) => {
7779
this.recipes = data;
7880
this.recipesChanged.next(this.recipes.slice());
7981
}, (error) => {
8082
alert("Error : " + error.error.error);
81-
})
83+
});
8284
});
8385
}
8486
}

src/app/services/shopping-list.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable} from "@angular/core";
22
import {IngredientModel} from "../common/Ingredient.model";
33
import {Subject} from "rxjs";
44
import {HttpClient} from "@angular/common/http";
5-
import {APP_CONSTANTS} from "../constants/app.constants";
5+
import {environment} from "../../environments/environment";
66

77
@Injectable({
88
providedIn: 'root'
@@ -20,6 +20,8 @@ export class ShoppingListService {
2020

2121
private ingredients: IngredientModel [] = [];
2222

23+
APP_CONSTANTS = environment;
24+
2325
constructor(private http: HttpClient) {
2426

2527
}
@@ -46,8 +48,10 @@ export class ShoppingListService {
4648

4749
// Add ingredients coming from the
4850
addIngredients(addedIngredients: IngredientModel[]) {
49-
this.ingredients.push(...addedIngredients);
50-
this.updateIngredients();
51+
if(addedIngredients.length>0) {
52+
this.ingredients.push(...addedIngredients);
53+
this.updateIngredients();
54+
}
5155
}
5256

5357
deleteIngredient(index: number) {
@@ -56,7 +60,7 @@ export class ShoppingListService {
5660
}
5761

5862
getIngredientsFromServer() {
59-
this.http.get<IngredientModel[]>(`${APP_CONSTANTS.FIREBASE_BASE_URL}/ingredients.json`)
63+
this.http.get<IngredientModel[]>(`${this.APP_CONSTANTS.FIREBASE_BASE_URL}/ingredients.json`)
6064
.subscribe((data) => {
6165
this.ingredients = data ? data : [];
6266
this.ingredientsChanged.next(this.ingredients.slice())
@@ -66,7 +70,7 @@ export class ShoppingListService {
6670
updateIngredients() {
6771
let allIngredients: IngredientModel[] = this.getIngredients();
6872
// returns observable.
69-
return this.http.put<IngredientModel[]>(`${APP_CONSTANTS.FIREBASE_BASE_URL}/ingredients.json`, allIngredients)
73+
return this.http.put<IngredientModel[]>(`${this.APP_CONSTANTS.FIREBASE_BASE_URL}/ingredients.json`, allIngredients)
7074
.subscribe((data) => {
7175
if(data && data.length > 0) {
7276
this.ingredients = data;

src/environments/environment.prod.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export const environment = {
2-
production: true
2+
production: true,
3+
FIREBASE_BASE_URL : 'https://ng-app-e6a4b-default-rtdb.firebaseio.com',
4+
//FIREBASE_SIGNUP_URL: 'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]',
5+
// query params will be appended later in the request
6+
FIREBASE_SIGNUP_URL: 'https://identitytoolkit.googleapis.com/v1/accounts:signUp',
7+
FIREBASE_SIGNIN_URL: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword',
8+
FIREBASE_AUTH_API_KEY: 'AIzaSyC2HFOQeQ9eh_-fTZhWk85pxiP0tiDpaL4'
39
};

src/environments/environment.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// This file can be replaced during build by using the `fileReplacements` array.
22
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
33
// The list of file replacements can be found in `angular.json`.
4-
54
export const environment = {
6-
production: false
5+
production: false,
6+
FIREBASE_BASE_URL : 'https://ng-app-e6a4b-default-rtdb.firebaseio.com',
7+
//FIREBASE_SIGNUP_URL: 'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]',
8+
// query params will be appended later in the request
9+
FIREBASE_SIGNUP_URL: 'https://identitytoolkit.googleapis.com/v1/accounts:signUp',
10+
FIREBASE_SIGNIN_URL: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword',
11+
FIREBASE_AUTH_API_KEY: 'AIzaSyC2HFOQeQ9eh_-fTZhWk85pxiP0tiDpaL4'
712
};
813

914
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy