├── src
├── assets
│ ├── .gitkeep
│ └── images
│ │ ├── filler.png
│ │ ├── facebook.svg
│ │ ├── lock.svg
│ │ ├── email.svg
│ │ └── google.svg
├── app
│ ├── app.component.css
│ ├── email
│ │ ├── email.component.css
│ │ ├── email.component.html
│ │ ├── email.component.spec.ts
│ │ └── email.component.ts
│ ├── signup
│ │ ├── signup.component.css
│ │ ├── signup.component.html
│ │ ├── signup.component.spec.ts
│ │ └── signup.component.ts
│ ├── app.component.html
│ ├── app.component.ts
│ ├── members
│ │ ├── members.component.html
│ │ ├── members.component.css
│ │ ├── members.component.spec.ts
│ │ └── members.component.ts
│ ├── login
│ │ ├── login.component.html
│ │ ├── login.component.spec.ts
│ │ ├── login.component.css
│ │ └── login.component.ts
│ ├── auth.service.ts
│ ├── app.routes.ts
│ ├── app.component.spec.ts
│ ├── app.module.ts
│ └── router.animations.ts
├── favicon.ico
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── main.ts
├── tsconfig.json
├── index.html
├── polyfills.ts
├── test.ts
└── styles.css
├── e2e
├── app.po.ts
├── app.e2e-spec.ts
└── tsconfig.json
├── .editorconfig
├── README.md
├── .gitignore
├── protractor.conf.js
├── karma.conf.js
├── angular-cli.json
├── package.json
└── tslint.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/email/email.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/signup/signup.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/designcourse/angular-auth-demo/HEAD/src/favicon.ico
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/assets/images/filler.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/designcourse/angular-auth-demo/HEAD/src/assets/images/filler.png
--------------------------------------------------------------------------------
/e2e/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, element, by } from 'protractor';
2 |
3 | export class MyauthappPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent {
9 | title = 'app works!';
10 | }
11 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/src/app/members/members.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { MyauthappPage } from './app.po';
2 |
3 | describe('myauthapp App', function() {
4 | let page: MyauthappPage;
5 |
6 | beforeEach(() => {
7 | page = new MyauthappPage();
8 | });
9 |
10 | it('should display message saying app works', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('app works!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import './polyfills.ts';
2 |
3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
4 | import { enableProdMode } from '@angular/core';
5 | import { environment } from './environments/environment';
6 | import { AppModule } from './app/app.module';
7 |
8 | if (environment.production) {
9 | enableProdMode();
10 | }
11 |
12 | platformBrowserDynamic().bootstrapModule(AppModule);
13 |
--------------------------------------------------------------------------------
/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "declaration": false,
5 | "emitDecoratorMetadata": true,
6 | "experimentalDecorators": true,
7 | "module": "commonjs",
8 | "moduleResolution": "node",
9 | "outDir": "../dist/out-tsc-e2e",
10 | "sourceMap": true,
11 | "target": "es5",
12 | "typeRoots": [
13 | "../node_modules/@types"
14 | ]
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/src/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": "",
4 | "declaration": false,
5 | "emitDecoratorMetadata": true,
6 | "experimentalDecorators": true,
7 | "lib": ["es6", "dom"],
8 | "mapRoot": "./",
9 | "module": "es6",
10 | "moduleResolution": "node",
11 | "outDir": "../dist/out-tsc",
12 | "sourceMap": true,
13 | "target": "es5",
14 | "typeRoots": [
15 | "../node_modules/@types"
16 | ]
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/assets/images/facebook.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/login/login.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Angular Firebase Authentication
2 |
3 | 
4 |
5 | Check out a demo here: [Angular Authentication Example](https://coursetro.com/preview/angular-auth-demo/)
6 |
7 | Read (and watch) the tutorial here: [Angular Authentication Tutorial](https://coursetro.com/posts/code/32/Create-a-Full-Angular-Authentication-System-with-Firebase)
8 |
9 | Clone this repo to get up and running! Check out more [Angular Tutorials](https://coursetro.com) at our site.
10 |
--------------------------------------------------------------------------------
/src/app/members/members.component.css:
--------------------------------------------------------------------------------
1 | #toolbar {
2 | padding:0;
3 | width:70%;
4 | margin-left:-35%;
5 | }
6 |
7 | header {
8 | background:#3B8598;
9 | width:100%;
10 | }
11 |
12 | .basic-btn {
13 | width:100px;
14 | margin:0;
15 | }
16 |
17 | #page {
18 | padding:3em;
19 | margin:0;
20 | }
21 |
22 | #page img {
23 | margin-top:30px;
24 | }
25 |
26 | h2 {
27 | margin:0;
28 | }
29 |
30 |
31 | @media (max-width: 600px) {
32 | #page {
33 | padding:1em;
34 | }
35 | #toolbar {
36 | width:90%;
37 | margin-left: -45%;
38 | }
39 | }
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Myauthapp
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/app/signup/signup.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 |
7 | # dependencies
8 | /node_modules
9 |
10 | # IDEs and editors
11 | /.idea
12 | .project
13 | .classpath
14 | .c9/
15 | *.launch
16 | .settings/
17 |
18 | # IDE - VSCode
19 | .vscode/
20 | !.vscode/settings.json
21 | !.vscode/tasks.json
22 | !.vscode/launch.json
23 | !.vscode/extensions.json
24 |
25 | # misc
26 | /.sass-cache
27 | /connect.lock
28 | /coverage/*
29 | /libpeerconnection.log
30 | npm-debug.log
31 | testem.log
32 | /typings
33 |
34 | # e2e
35 | /e2e/*.js
36 | /e2e/*.map
37 |
38 | #System Files
39 | .DS_Store
40 | Thumbs.db
41 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | // This file includes polyfills needed by Angular and is loaded before
2 | // the app. You can add your own extra polyfills to this file.
3 | import 'core-js/es6/symbol';
4 | import 'core-js/es6/object';
5 | import 'core-js/es6/function';
6 | import 'core-js/es6/parse-int';
7 | import 'core-js/es6/parse-float';
8 | import 'core-js/es6/number';
9 | import 'core-js/es6/math';
10 | import 'core-js/es6/string';
11 | import 'core-js/es6/date';
12 | import 'core-js/es6/array';
13 | import 'core-js/es6/regexp';
14 | import 'core-js/es6/map';
15 | import 'core-js/es6/set';
16 | import 'core-js/es6/reflect';
17 |
18 | import 'core-js/es7/reflect';
19 | import 'zone.js/dist/zone';
20 |
--------------------------------------------------------------------------------
/src/app/email/email.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/auth.service.ts:
--------------------------------------------------------------------------------
1 | import { CanActivate, Router } from '@angular/router';
2 | import { AngularFireAuth } from "angularfire2/angularfire2";
3 | import { Injectable } from "@angular/core";
4 | import { Observable } from "rxjs/Rx";
5 | import 'rxjs/add/operator/do';
6 | import 'rxjs/add/operator/map';
7 | import 'rxjs/add/operator/take';
8 |
9 | @Injectable()
10 | export class AuthGuard implements CanActivate {
11 |
12 | constructor(private auth: AngularFireAuth, private router: Router) {}
13 |
14 | canActivate(): Observable {
15 | return Observable.from(this.auth)
16 | .take(1)
17 | .map(state => !!state)
18 | .do(authenticated => {
19 | if
20 | (!authenticated) this.router.navigate([ '/login' ]);
21 | })
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/src/app/email/email.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { EmailComponent } from './email.component';
7 |
8 | describe('EmailComponent', () => {
9 | let component: EmailComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ EmailComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(EmailComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/login/login.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { LoginComponent } from './login.component';
7 |
8 | describe('LoginComponent', () => {
9 | let component: LoginComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ LoginComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(LoginComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | /*global jasmine */
5 | var SpecReporter = require('jasmine-spec-reporter');
6 |
7 | exports.config = {
8 | allScriptsTimeout: 11000,
9 | specs: [
10 | './e2e/**/*.e2e-spec.ts'
11 | ],
12 | capabilities: {
13 | 'browserName': 'chrome'
14 | },
15 | directConnect: true,
16 | baseUrl: 'http://localhost:4200/',
17 | framework: 'jasmine',
18 | jasmineNodeOpts: {
19 | showColors: true,
20 | defaultTimeoutInterval: 30000,
21 | print: function() {}
22 | },
23 | useAllAngular2AppRoots: true,
24 | beforeLaunch: function() {
25 | require('ts-node').register({
26 | project: 'e2e'
27 | });
28 | },
29 | onPrepare: function() {
30 | jasmine.getEnv().addReporter(new SpecReporter());
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/src/app/signup/signup.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { SignupComponent } from './signup.component';
7 |
8 | describe('SignupComponent', () => {
9 | let component: SignupComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ SignupComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(SignupComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/members/members.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 | import { By } from '@angular/platform-browser';
4 | import { DebugElement } from '@angular/core';
5 |
6 | import { MembersComponent } from './members.component';
7 |
8 | describe('MembersComponent', () => {
9 | let component: MembersComponent;
10 | let fixture: ComponentFixture;
11 |
12 | beforeEach(async(() => {
13 | TestBed.configureTestingModule({
14 | declarations: [ MembersComponent ]
15 | })
16 | .compileComponents();
17 | }));
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(MembersComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/app/app.routes.ts:
--------------------------------------------------------------------------------
1 | import { ModuleWithProviders } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | import { AppComponent } from './app.component';
5 | import { LoginComponent } from './login/login.component';
6 | import { MembersComponent } from './members/members.component';
7 | import { AuthGuard } from './auth.service';
8 | import { SignupComponent } from './signup/signup.component';
9 | import { EmailComponent } from './email/email.component';
10 |
11 | export const router: Routes = [
12 | { path: '', redirectTo: 'login', pathMatch: 'full' },
13 | { path: 'login', component: LoginComponent },
14 | { path: 'signup', component: SignupComponent },
15 | { path: 'login-email', component: EmailComponent },
16 | { path: 'members', component: MembersComponent, canActivate: [AuthGuard] }
17 |
18 | ]
19 |
20 | export const routes: ModuleWithProviders = RouterModule.forRoot(router);
--------------------------------------------------------------------------------
/src/app/login/login.component.css:
--------------------------------------------------------------------------------
1 | #lock {
2 | width:40%;
3 | margin: 1.5em auto 4em auto;
4 | display:block;
5 | }
6 |
7 | #fb {
8 | background:#3B5998 url('assets/images/facebook.svg') no-repeat 14px 6px;
9 | background-size: 47px;
10 | color:#fff;
11 | }
12 |
13 | #google {
14 | border: 1px solid #95989A;
15 | background: #fff url('assets/images/google.svg') no-repeat 25px;
16 | background-size: 25px;
17 | }
18 |
19 | #email {
20 | background: #ECECEC url('assets/images/email.svg') no-repeat 25px;
21 | background-size: 25px;
22 | }
23 |
24 | @media (max-width: 600px) {
25 | #page {
26 | padding:1em;
27 | }
28 | #toolbar {
29 | width:90%;
30 | margin-left: -45%;
31 | }
32 | #fb {
33 | background:#3B5998;
34 | }
35 |
36 | #google {
37 | background: #fff;
38 | }
39 |
40 | #email {
41 | background: #ECECEC;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/app/members/members.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AngularFire, AuthProviders, AuthMethods } from 'angularfire2';
3 | import { Router } from '@angular/router';
4 | import { moveIn, fallIn, moveInLeft } from '../router.animations';
5 |
6 | @Component({
7 | selector: 'app-members',
8 | templateUrl: './members.component.html',
9 | styleUrls: ['./members.component.css'],
10 | animations: [moveIn(), fallIn(), moveInLeft()],
11 | host: {'[@moveIn]': ''}
12 | })
13 | export class MembersComponent implements OnInit {
14 | name: any;
15 | state: string = '';
16 |
17 | constructor(public af: AngularFire,private router: Router) {
18 |
19 | this.af.auth.subscribe(auth => {
20 | if(auth) {
21 | this.name = auth;
22 | }
23 | });
24 |
25 | }
26 |
27 | logout() {
28 | this.af.auth.logout();
29 | this.router.navigateByUrl('/login');
30 | }
31 |
32 |
33 | ngOnInit() {
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/app/signup/signup.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AngularFire, AuthProviders, AuthMethods } from 'angularfire2';
3 | import { Router } from '@angular/router';
4 | import { moveIn, fallIn } from '../router.animations';
5 |
6 | @Component({
7 | selector: 'app-signup',
8 | templateUrl: './signup.component.html',
9 | styleUrls: ['./signup.component.css'],
10 | animations: [moveIn(), fallIn()],
11 | host: {'[@moveIn]': ''}
12 | })
13 | export class SignupComponent implements OnInit {
14 |
15 | state: string = '';
16 | error: any;
17 |
18 | constructor(public af: AngularFire,private router: Router) {
19 |
20 | }
21 |
22 | onSubmit(formData) {
23 | if(formData.valid) {
24 | console.log(formData.value);
25 | this.af.auth.createUser({
26 | email: formData.value.email,
27 | password: formData.value.password
28 | }).then(
29 | (success) => {
30 | this.router.navigate(['/members'])
31 | }).catch(
32 | (err) => {
33 | this.error = err;
34 | })
35 | }
36 | }
37 |
38 | ngOnInit() {
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | import './polyfills.ts';
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare var __karma__: any;
17 | declare var require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | /* tslint:disable:no-unused-variable */
2 |
3 | import { TestBed, async } from '@angular/core/testing';
4 | import { AppComponent } from './app.component';
5 |
6 | describe('AppComponent', () => {
7 | beforeEach(() => {
8 | TestBed.configureTestingModule({
9 | declarations: [
10 | AppComponent
11 | ],
12 | });
13 | TestBed.compileComponents();
14 | });
15 |
16 | it('should create the app', async(() => {
17 | const fixture = TestBed.createComponent(AppComponent);
18 | const app = fixture.debugElement.componentInstance;
19 | expect(app).toBeTruthy();
20 | }));
21 |
22 | it(`should have as title 'app works!'`, async(() => {
23 | const fixture = TestBed.createComponent(AppComponent);
24 | const app = fixture.debugElement.componentInstance;
25 | expect(app.title).toEqual('app works!');
26 | }));
27 |
28 | it('should render title in a h1 tag', async(() => {
29 | const fixture = TestBed.createComponent(AppComponent);
30 | fixture.detectChanges();
31 | const compiled = fixture.debugElement.nativeElement;
32 | expect(compiled.querySelector('h1').textContent).toContain('app works!');
33 | }));
34 | });
35 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/0.13/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', 'angular-cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-remap-istanbul'),
12 | require('angular-cli/plugins/karma')
13 | ],
14 | files: [
15 | { pattern: './src/test.ts', watched: false }
16 | ],
17 | preprocessors: {
18 | './src/test.ts': ['angular-cli']
19 | },
20 | mime: {
21 | 'text/x-typescript': ['ts','tsx']
22 | },
23 | remapIstanbulReporter: {
24 | reports: {
25 | html: 'coverage',
26 | lcovonly: './coverage/coverage.lcov'
27 | }
28 | },
29 | angularCli: {
30 | config: './angular-cli.json',
31 | environment: 'dev'
32 | },
33 | reporters: config.angularCli && config.angularCli.codeCoverage
34 | ? ['progress', 'karma-remap-istanbul']
35 | : ['progress'],
36 | port: 9876,
37 | colors: true,
38 | logLevel: config.LOG_INFO,
39 | autoWatch: true,
40 | browsers: ['Chrome'],
41 | singleRun: false
42 | });
43 | };
44 |
--------------------------------------------------------------------------------
/src/assets/images/lock.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/angular-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "project": {
3 | "version": "1.0.0-beta.25.5",
4 | "name": "myauthapp"
5 | },
6 | "apps": [
7 | {
8 | "root": "src",
9 | "outDir": "dist",
10 | "assets": [
11 | "assets",
12 | "favicon.ico"
13 | ],
14 | "index": "index.html",
15 | "main": "main.ts",
16 | "test": "test.ts",
17 | "tsconfig": "tsconfig.json",
18 | "prefix": "app",
19 | "mobile": false,
20 | "styles": [
21 | "styles.css"
22 | ],
23 | "scripts": [],
24 | "environments": {
25 | "source": "environments/environment.ts",
26 | "dev": "environments/environment.ts",
27 | "prod": "environments/environment.prod.ts"
28 | }
29 | }
30 | ],
31 | "addons": [],
32 | "packages": [],
33 | "e2e": {
34 | "protractor": {
35 | "config": "./protractor.conf.js"
36 | }
37 | },
38 | "test": {
39 | "karma": {
40 | "config": "./karma.conf.js"
41 | }
42 | },
43 | "defaults": {
44 | "styleExt": "css",
45 | "prefixInterfaces": false,
46 | "inline": {
47 | "style": false,
48 | "template": false
49 | },
50 | "spec": {
51 | "class": false,
52 | "component": true,
53 | "directive": true,
54 | "module": false,
55 | "pipe": true,
56 | "service": true
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { HttpModule } from '@angular/http';
5 | import { AngularFireModule } from 'angularfire2';
6 | import { AppComponent } from './app.component';
7 | import { LoginComponent } from './login/login.component';
8 | import { EmailComponent } from './email/email.component';
9 | import { SignupComponent } from './signup/signup.component';
10 | import { MembersComponent } from './members/members.component';
11 | import { AuthGuard } from './auth.service';
12 | import { routes } from './app.routes';
13 |
14 |
15 | // Must export the config
16 | export const firebaseConfig = {
17 | apiKey: 'AIzaSyAaTLLTBfT8-tlCXOKlp4LrwQzhVWjbM1Q',
18 | authDomain: 'angular-pre.firebaseapp.com',
19 | databaseURL: 'https://angular-pre.firebaseio.com',
20 | storageBucket: 'angular-pre.appspot.com',
21 | messagingSenderId: '796422970338'
22 | };
23 |
24 | @NgModule({
25 | declarations: [
26 | AppComponent,
27 | LoginComponent,
28 | EmailComponent,
29 | SignupComponent,
30 | MembersComponent
31 | ],
32 | imports: [
33 | BrowserModule,
34 | FormsModule,
35 | HttpModule,
36 | AngularFireModule.initializeApp(firebaseConfig),
37 | routes
38 | ],
39 | providers: [AuthGuard],
40 | bootstrap: [AppComponent]
41 | })
42 | export class AppModule { }
43 |
--------------------------------------------------------------------------------
/src/app/router.animations.ts:
--------------------------------------------------------------------------------
1 | import {trigger, state, animate, style, transition} from '@angular/core';
2 |
3 | export function moveIn() {
4 | return trigger('moveIn', [
5 | state('void', style({position: 'fixed', width: '100%'}) ),
6 | state('*', style({position: 'fixed', width: '100%'}) ),
7 | transition(':enter', [
8 | style({opacity:'0', transform: 'translateX(100px)'}),
9 | animate('.6s ease-in-out', style({opacity:'1', transform: 'translateX(0)'}))
10 | ]),
11 | transition(':leave', [
12 | style({opacity:'1', transform: 'translateX(0)'}),
13 | animate('.3s ease-in-out', style({opacity:'0', transform: 'translateX(-200px)'}))
14 | ])
15 | ]);
16 | }
17 |
18 | export function fallIn() {
19 | return trigger('fallIn', [
20 | transition(':enter', [
21 | style({opacity:'0', transform: 'translateY(40px)'}),
22 | animate('.4s .2s ease-in-out', style({opacity:'1', transform: 'translateY(0)'}))
23 | ]),
24 | transition(':leave', [
25 | style({opacity:'1', transform: 'translateX(0)'}),
26 | animate('.3s ease-in-out', style({opacity:'0', transform: 'translateX(-200px)'}))
27 | ])
28 | ]);
29 | }
30 |
31 | export function moveInLeft() {
32 | return trigger('moveInLeft', [
33 | transition(':enter', [
34 | style({opacity:'0', transform: 'translateX(-100px)'}),
35 | animate('.6s .2s ease-in-out', style({opacity:'1', transform: 'translateX(0)'}))
36 | ])
37 | ]);
38 | }
--------------------------------------------------------------------------------
/src/app/email/email.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { AngularFire, AuthProviders, AuthMethods } from 'angularfire2';
3 | import { Router } from '@angular/router';
4 | import { moveIn, fallIn } from '../router.animations';
5 |
6 | @Component({
7 | selector: 'app-email',
8 | templateUrl: './email.component.html',
9 | styleUrls: ['./email.component.css'],
10 | animations: [moveIn(), fallIn()],
11 | host: {'[@moveIn]': ''}
12 | })
13 | export class EmailComponent implements OnInit {
14 |
15 | state: string = '';
16 | error: any;
17 |
18 | constructor(public af: AngularFire,private router: Router) {
19 | this.af.auth.subscribe(auth => {
20 | if(auth) {
21 | this.router.navigateByUrl('/members');
22 | }
23 | });
24 | }
25 |
26 |
27 | onSubmit(formData) {
28 | if(formData.valid) {
29 | console.log(formData.value);
30 | this.af.auth.login({
31 | email: formData.value.email,
32 | password: formData.value.password
33 | },
34 | {
35 | provider: AuthProviders.Password,
36 | method: AuthMethods.Password,
37 | }).then(
38 | (success) => {
39 | console.log(success);
40 | this.router.navigate(['/members']);
41 | }).catch(
42 | (err) => {
43 | console.log(err);
44 | this.error = err;
45 | })
46 | }
47 | }
48 |
49 | ngOnInit() {
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/app/login/login.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, HostBinding } from '@angular/core';
2 | import { AngularFire, AuthProviders, AuthMethods } from 'angularfire2';
3 | import { Router } from '@angular/router';
4 | import { moveIn } from '../router.animations';
5 |
6 | @Component({
7 | selector: 'app-login',
8 | templateUrl: './login.component.html',
9 | styleUrls: ['./login.component.css'],
10 | animations: [moveIn()],
11 | host: {'[@moveIn]': ''}
12 | })
13 | export class LoginComponent implements OnInit {
14 |
15 | error: any;
16 | constructor(public af: AngularFire,private router: Router) {
17 |
18 | this.af.auth.subscribe(auth => {
19 | if(auth) {
20 | this.router.navigateByUrl('/members');
21 | }
22 | });
23 |
24 | }
25 |
26 | loginFb() {
27 | this.af.auth.login({
28 | provider: AuthProviders.Facebook,
29 | method: AuthMethods.Popup,
30 | }).then(
31 | (success) => {
32 | this.router.navigate(['/members']);
33 | }).catch(
34 | (err) => {
35 | this.error = err;
36 | })
37 | }
38 |
39 | loginGoogle() {
40 | this.af.auth.login({
41 | provider: AuthProviders.Google,
42 | method: AuthMethods.Popup,
43 | }).then(
44 | (success) => {
45 | this.router.navigate(['/members']);
46 | }).catch(
47 | (err) => {
48 | this.error = err;
49 | })
50 | }
51 |
52 |
53 | ngOnInit() {
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/assets/images/email.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "myauthapp",
3 | "version": "0.0.0",
4 | "license": "MIT",
5 | "angular-cli": {},
6 | "scripts": {
7 | "ng": "ng",
8 | "start": "ng serve",
9 | "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
10 | "test": "ng test",
11 | "pree2e": "webdriver-manager update --standalone false --gecko false",
12 | "e2e": "protractor"
13 | },
14 | "private": true,
15 | "dependencies": {
16 | "@angular/common": "^2.3.1",
17 | "@angular/compiler": "^2.3.1",
18 | "@angular/core": "^2.3.1",
19 | "@angular/forms": "^2.3.1",
20 | "@angular/http": "^2.3.1",
21 | "@angular/platform-browser": "^2.3.1",
22 | "@angular/platform-browser-dynamic": "^2.3.1",
23 | "@angular/router": "^3.3.1",
24 | "angularfire2": "^2.0.0-beta.7",
25 | "core-js": "^2.4.1",
26 | "firebase": "^3.6.5",
27 | "rxjs": "^5.0.1",
28 | "ts-helpers": "^1.1.1",
29 | "zone.js": "^0.7.2"
30 | },
31 | "devDependencies": {
32 | "@angular/compiler-cli": "^2.3.1",
33 | "@types/jasmine": "2.5.38",
34 | "@types/node": "^6.0.42",
35 | "angular-cli": "1.0.0-beta.25.5",
36 | "codelyzer": "~2.0.0-beta.1",
37 | "jasmine-core": "2.5.2",
38 | "jasmine-spec-reporter": "2.5.0",
39 | "karma": "1.2.0",
40 | "karma-chrome-launcher": "^2.0.0",
41 | "karma-cli": "^1.0.1",
42 | "karma-jasmine": "^1.0.2",
43 | "karma-remap-istanbul": "^0.2.1",
44 | "protractor": "~4.0.13",
45 | "ts-node": "1.2.1",
46 | "tslint": "^4.3.0",
47 | "typescript": "~2.0.3"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | body {
3 | background:#E2E4E6;
4 | padding-top:4em;
5 | }
6 |
7 | .form-container {
8 | background:white;
9 | padding:3.5em;
10 | width:500px;
11 | position:fixed;
12 | left:50%;
13 | margin-left:-250px;
14 | }
15 |
16 | button {
17 | padding:1.2em;
18 | width:100%;
19 | cursor:pointer;
20 | margin-bottom:15px;
21 | font-size:1.3em;
22 | }
23 |
24 | .basic-btn {
25 | background: #3B8598;
26 | color:white;
27 | }
28 |
29 | input.txt {
30 | background:#fff !important;
31 | padding:1.3em 1em;
32 | font-size:1.3em;
33 | border: 1px solid #BBBBBB;
34 | }
35 |
36 | h2 {
37 | margin: 1.7em 0 .9em 0;
38 | }
39 |
40 | .alc {
41 | text-align:center;
42 | display:block;
43 | margin: 15px 0;
44 | }
45 |
46 | .error {
47 | background:#f1f0ef;
48 | padding:1em;
49 | width:100%;
50 | display:block;
51 | margin-bottom:20px;
52 | }
53 |
54 | #goback {
55 | font-weight:bold;
56 | text-transform:uppercase;
57 | font-size:.8em;
58 | color:#3B8598;
59 | }
60 | #goback span {
61 | font-size:1em;
62 | }
63 |
64 |
65 |
66 | .loading {
67 | width: 30px;
68 | height: 30px;
69 | border: 5px solid #ccc;
70 | position: fixed;
71 | left: 50%;
72 | margin-left: -20px;
73 | top: 50%;
74 | margin-top: -20px;
75 | border-radius: 50%;
76 | }
77 |
78 |
79 | .loading:after {
80 | content: '';
81 | position: absolute;
82 | width: 40px;
83 | height: 10px;
84 | background: #E2E4E6;
85 | top: 10px;
86 | left: -5px;
87 | animation: spin 1.2s infinite;
88 | }
89 |
90 | @keyframes spin {
91 | 100% {
92 | transform: rotate(360deg);
93 | }
94 | }
95 |
96 |
97 | @media (max-width: 600px) {
98 | body {
99 | padding-top:1.2em;
100 | }
101 |
102 | .form-container {
103 | padding:1.2em;
104 | width:90%;
105 | margin-left:-45%;
106 | }
107 | button {
108 | font-size:1em;
109 | }
110 | }
--------------------------------------------------------------------------------
/src/assets/images/google.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "callable-types": true,
7 | "class-name": true,
8 | "comment-format": [
9 | true,
10 | "check-space"
11 | ],
12 | "curly": true,
13 | "eofline": true,
14 | "forin": true,
15 | "import-blacklist": [true, "rxjs"],
16 | "import-spacing": true,
17 | "indent": [
18 | true,
19 | "spaces"
20 | ],
21 | "interface-over-type-literal": true,
22 | "label-position": true,
23 | "max-line-length": [
24 | true,
25 | 140
26 | ],
27 | "member-access": false,
28 | "member-ordering": [
29 | true,
30 | "static-before-instance",
31 | "variables-before-functions"
32 | ],
33 | "no-arg": true,
34 | "no-bitwise": true,
35 | "no-console": [
36 | true,
37 | "debug",
38 | "info",
39 | "time",
40 | "timeEnd",
41 | "trace"
42 | ],
43 | "no-construct": true,
44 | "no-debugger": true,
45 | "no-duplicate-variable": true,
46 | "no-empty": false,
47 | "no-empty-interface": true,
48 | "no-eval": true,
49 | "no-inferrable-types": true,
50 | "no-shadowed-variable": true,
51 | "no-string-literal": false,
52 | "no-string-throw": true,
53 | "no-switch-case-fall-through": true,
54 | "no-trailing-whitespace": true,
55 | "no-unused-expression": true,
56 | "no-use-before-declare": true,
57 | "no-var-keyword": true,
58 | "object-literal-sort-keys": false,
59 | "one-line": [
60 | true,
61 | "check-open-brace",
62 | "check-catch",
63 | "check-else",
64 | "check-whitespace"
65 | ],
66 | "prefer-const": true,
67 | "quotemark": [
68 | true,
69 | "single"
70 | ],
71 | "radix": true,
72 | "semicolon": [
73 | "always"
74 | ],
75 | "triple-equals": [
76 | true,
77 | "allow-null-check"
78 | ],
79 | "typedef-whitespace": [
80 | true,
81 | {
82 | "call-signature": "nospace",
83 | "index-signature": "nospace",
84 | "parameter": "nospace",
85 | "property-declaration": "nospace",
86 | "variable-declaration": "nospace"
87 | }
88 | ],
89 | "typeof-compare": true,
90 | "unified-signatures": true,
91 | "variable-name": false,
92 | "whitespace": [
93 | true,
94 | "check-branch",
95 | "check-decl",
96 | "check-operator",
97 | "check-separator",
98 | "check-type"
99 | ],
100 |
101 | "directive-selector": [true, "attribute", "app", "camelCase"],
102 | "component-selector": [true, "element", "app", "kebab-case"],
103 | "use-input-property-decorator": true,
104 | "use-output-property-decorator": true,
105 | "use-host-property-decorator": true,
106 | "no-input-rename": true,
107 | "no-output-rename": true,
108 | "use-life-cycle-interface": true,
109 | "use-pipe-transform-interface": true,
110 | "component-class-suffix": true,
111 | "directive-class-suffix": true,
112 | "no-access-missing-member": true,
113 | "templates-use-public": true,
114 | "invoke-injectable": true
115 | }
116 | }
117 |
--------------------------------------------------------------------------------