- Go to
console.firebase.com
and login if necessary - create a new project called "code-mentoring-edition1".
- Once inside the project, click on the "Project Overview" button on the top-left
- click on the "Add App" button, just bellow the name of your project (code-mentoring-edition1).
- Amongst the icons, choose "Web" (the last one)
- When asked for it, also call the app "code-mentoring-edition1"
- check the box for Hosting, and set the url to whatever you wish.
- click the "Register the App" button and finish the process clicking on "next" and "continue to console"
- back to the console, in "Project Overview", click on the newly created app icon,below the project name and on the gear icon (settings)
- Once in the project settings, scroll down to the app settings and from the "Automatic", "CDN", "Config", choose "Config"
- Copy the snippet and paste in somewhere, we're going to use it later on.
if you haven't followed along during last session, those are the steps to take to create the project:
- open a terminal in the directory you want your project to be located in.
- run
ng new code-mentoring-edition1 --routing --style sccs
- Once the process is done, run
cd code-mentoring-edition1
, then runcode .
to open the project in VSCode. - Open VSCode terminal (View/Terminal) and inside it, run
ng add @angular/fire
. It might ask you for authentication & permissions. When asked, choose the code-mentoring-edition1 project from the list. - run
npm i @types/firebase --save-dev
to install the types for firebase as a development dependency. - in the app folder, create the following directories:
- core
- shared
- sections
- in the core folder, create the following directories:
- models
- pipes
- services
- guards
- in the shared folder, create a services directory
-
in the tsconfig.json file, add the the following snippet in the
compilerOptions
:"strictNullChecks": false, "paths": { "@env": ["src/environments/environment"], "@shared/*": ["src/app/shared/*"], "@core/*": ["src/app/core/*"], "@sections/*": ["src/app/sections/*"] }, "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "typeRoots": ["node_modules/@types"],
-
In the root folder of the project, if it doesn't exist, create a file named .editorconfig (starting with a dot). In that file,
- under
[*]
, add the following configs:quote_type = single max_line_length = 140
- under
[*.ts]
, addstrictNullCheck = false
- under
-
in the tslint.json file, change
rules.variable-name
to :"options": [ "allow-leading-underscore", "allow-pascal-case", "ban-keywords", "check-format", "require-const-for-all-caps" ]
-
in the environment.ts file, add the
firebaseConfig
object we got from the firestore console, to theenvironment
constant. -
Also add a variable called
collections
than holds firestore collections names (venues
,users
,checksIn
). Once done, theenvironment
constant should look like this:export const environment = { production: false, firebaseConfig: { apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXX', authDomain: '??????????', projectId: 'code-mentoring-edition1', storageBucket: 'code-mentoring-edition1.appspot.com', messagingSenderId: 'XXXXXXXXX', appId: 'XXXXXXXXXXXXXXXXXXX', measurementId: 'XXXXXXXXXXXXXXXXxxx', }, collections: { venues: 'venues', users: 'users', checksIn: 'checksIn', }, };
-
Repeat the 2 previous points for the environment.prod.ts file
- create the core module:
ng g m core
- inside core.module.ts, define a constant array called
module
and add the necessary modules, like thisconst modules = [AngularFireAuthModule, AngularFirestoreModule];
- in the
imports
array of the decorator@NgModule
add the following:CommonModule
...modules
AngularFireModule.initializeApp(environment.firebaseConfig)
- in the
exports
array, add the following:...modules
- in the
providers
array, add the following:AngularFirestore
AuthService
- in the
constructor
of the module, add the following line:constructor() { firebase.setLogLevel('info'); }
- create the service using
ng g s core/services/users
- add the
AngularFireStore
provider using dependency injection: - add the
UsersService
to the providers of the core.module.ts file
- create the service using
ng g s core/services/auth
- add the
AngularFireAuth
provider using dependency injection:constructor(protected _afAuth: AngularFireAuth) {}
- add the
AuthService
to the providers of the core.module.ts file