Skip to content

Commit 3d5f962

Browse files
authored
Merge pull request auth0-blog#77 from blacksonic/master
Upgrade to Angular 2 final and update articles section in readme
2 parents 4474a12 + d7c6052 commit 3d5f962

File tree

10 files changed

+76
-65
lines changed

10 files changed

+76
-65
lines changed

Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ This sample shows how to create an angular 2 app that:
66
* **Calls APIs** authenticated and not.
77
* Extends the **RouterOutlet** for route pipeline changes.
88

9-
> You can **learn more about how it works [in this blogpost](https://auth0.com/blog/2015/05/14/creating-your-first-real-world-angular-2-app-from-authentication-to-calling-an-api-and-everything-in-between/)**
9+
You can **learn more about how it works in the following blogposts**
10+
11+
* [Angular 2 Authentication Tutorial](https://auth0.com/blog/angular-2-authentication/)
12+
* [Protecting Routes using Guards in Angular 2](http://blog.thoughtram.io/angular/2016/07/18/guards-in-angular-2.html)
13+
* [Angular 2 authentication revisited](https://medium.com/@blacksonic86/angular-2-authentication-revisited-611bf7373bf9)
1014

1115
## Running it
1216

package.json

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@
2424
},
2525
"homepage": "https://github.com/auth0/angular2-authentication-sample",
2626
"dependencies": {
27-
"@angular/common": "2.0.0-rc.3",
28-
"@angular/compiler": "2.0.0-rc.3",
29-
"@angular/core": "2.0.0-rc.3",
30-
"@angular/http": "2.0.0-rc.3",
31-
"@angular/platform-browser": "2.0.0-rc.3",
32-
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
33-
"@angular/platform-server": "2.0.0-rc.3",
34-
"@angular/router": "3.0.0-alpha.7",
35-
"angular2-jwt": "0.1.16",
36-
"bootstrap": "^3.3.6",
37-
"core-js": "^2.4.0",
38-
"es6-promise": "^3.1.2",
39-
"es6-shim": "^0.33.13",
40-
"es7-reflect-metadata": "^1.6.0",
27+
"@angular/common": "2.0.1",
28+
"@angular/compiler": "2.0.1",
29+
"@angular/core": "2.0.1",
30+
"@angular/forms": "2.0.1",
31+
"@angular/http": "2.0.1",
32+
"@angular/platform-browser": "2.0.1",
33+
"@angular/platform-browser-dynamic": "2.0.1",
34+
"@angular/platform-server": "2.0.1",
35+
"@angular/router": "3.0.1",
36+
"angular2-jwt": "0.1.23",
37+
"bootstrap": "^3.3.7",
38+
"core-js": "^2.4.1",
4139
"jwt-decode": "^2.0.1",
42-
"rxjs": "5.0.0-beta.6",
43-
"zone.js": "~0.6.12"
40+
"rxjs": "5.0.0-beta.12",
41+
"zone.js": "~0.6.25"
4442
},
4543
"devDependencies": {
46-
"css-loader": "^0.23.1",
44+
"css-loader": "^0.25.0",
4745
"exports-loader": "^0.6.3",
4846
"expose-loader": "^0.7.1",
4947
"file-loader": "^0.9.0",
@@ -52,14 +50,14 @@
5250
"raw-loader": "^0.5.1",
5351
"style-loader": "^0.13.1",
5452
"ts-loader": "^0.8.1",
55-
"tsconfig-lint": "^0.7.0",
53+
"tsconfig-lint": "^0.12.0",
5654
"tslint": "^3.7.1",
5755
"tslint-loader": "^2.1.3",
5856
"typedoc": "^0.4.3",
59-
"typescript": "~1.8.10",
57+
"typescript": "~2.0.3",
6058
"typings": "^1.3.0",
6159
"url-loader": "^0.5.7",
62-
"webpack": "^1.13.1",
63-
"webpack-dev-server": "^1.14.1"
60+
"webpack": "^1.13.2",
61+
"webpack-dev-server": "^1.16.1"
6462
}
6563
}

src/app.module.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { BrowserModule } from '@angular/platform-browser';
2+
import { RouterModule } from '@angular/router';
3+
import { HttpModule } from '@angular/http';
4+
import { FormsModule } from '@angular/forms';
5+
import { NgModule } from '@angular/core';
6+
7+
import { AUTH_PROVIDERS } from 'angular2-jwt';
8+
9+
import { AuthGuard } from './common/auth.guard';
10+
import { Home } from './home';
11+
import { Login } from './login';
12+
import { Signup } from './signup';
13+
import { App } from './app';
14+
15+
import { routes } from './app.routes';
16+
17+
@NgModule({
18+
bootstrap: [App],
19+
declarations: [
20+
Home, Login, Signup, App
21+
],
22+
imports: [
23+
HttpModule, BrowserModule, FormsModule,
24+
RouterModule.forRoot(routes, {
25+
useHash: true
26+
})
27+
],
28+
providers: [
29+
AuthGuard, ...AUTH_PROVIDERS
30+
]
31+
})
32+
export class AppModule {}

src/app.routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { RouterConfig } from '@angular/router';
1+
import { Routes } from '@angular/router';
22
import { Home } from './home';
33
import { Login } from './login';
44
import { Signup } from './signup';
55
import { AuthGuard } from './common/auth.guard';
66

7-
export const routes: RouterConfig = [
8-
{ path: '', component: Login },
7+
export const routes: Routes = [
8+
{ path: '', component: Login },
99
{ path: 'login', component: Login },
1010
{ path: 'signup', component: Signup },
1111
{ path: 'home', component: Home, canActivate: [AuthGuard] },

src/app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Component } from '@angular/core';
2-
import { Router, ROUTER_DIRECTIVES } from '@angular/router';
2+
import { Router } from '@angular/router';
33

44
const template = require('./app.html');
55

66
@Component({
77
selector: 'auth-app',
8-
template: template,
9-
directives: [ ROUTER_DIRECTIVES ]
8+
template: template
109
})
1110

1211
export class App {

src/home/home.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { CORE_DIRECTIVES } from '@angular/common';
3-
import { Http, Headers } from '@angular/http';
2+
import { Http } from '@angular/http';
43
import { Router } from '@angular/router';
54
import { AuthHttp } from 'angular2-jwt';
65

@@ -9,7 +8,6 @@ const template = require('./home.html');
98

109
@Component({
1110
selector: 'home',
12-
directives: [ CORE_DIRECTIVES ],
1311
template: template,
1412
styles: [ styles ]
1513
})
@@ -26,7 +24,7 @@ export class Home {
2624

2725
logout() {
2826
localStorage.removeItem('id_token');
29-
this.router.navigate(['/login']);
27+
this.router.navigate(['login']);
3028
}
3129

3230
callAnonymousApi() {

src/index.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
import { bootstrap } from '@angular/platform-browser-dynamic';
2-
import { provideRouter } from '@angular/router';
3-
import { FORM_PROVIDERS } from '@angular/common';
4-
import { HTTP_PROVIDERS } from '@angular/http';
5-
import { AUTH_PROVIDERS } from 'angular2-jwt';
6-
import { AuthGuard } from './common/auth.guard';
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
72

8-
import { App } from './app';
9-
import { routes } from './app.routes';
3+
import { AppModule } from './app.module';
104

11-
bootstrap(
12-
App,
13-
[
14-
provideRouter(routes),
15-
FORM_PROVIDERS,
16-
HTTP_PROVIDERS,
17-
AUTH_PROVIDERS,
18-
AuthGuard
19-
]
20-
);
5+
platformBrowserDynamic().bootstrapModule(AppModule);

src/login/login.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { Component } from '@angular/core';
2-
import { Router, ROUTER_DIRECTIVES } from '@angular/router';
3-
import { CORE_DIRECTIVES, FORM_DIRECTIVES } from '@angular/common';
4-
import { Http, Headers } from '@angular/http';
2+
import { Router } from '@angular/router';
3+
import { Http } from '@angular/http';
54
import { contentHeaders } from '../common/headers';
65

76
const styles = require('./login.css');
87
const template = require('./login.html');
98

109
@Component({
1110
selector: 'login',
12-
directives: [ ROUTER_DIRECTIVES, CORE_DIRECTIVES, FORM_DIRECTIVES ],
1311
template: template,
1412
styles: [ styles ]
1513
})
@@ -24,7 +22,7 @@ export class Login {
2422
.subscribe(
2523
response => {
2624
localStorage.setItem('id_token', response.json().id_token);
27-
this.router.navigate(['/home']);
25+
this.router.navigate(['home']);
2826
},
2927
error => {
3028
alert(error.text());
@@ -35,6 +33,6 @@ export class Login {
3533

3634
signup(event) {
3735
event.preventDefault();
38-
this.router.navigate(['/signup']);
36+
this.router.navigate(['signup']);
3937
}
4038
}

src/signup/signup.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component } from '@angular/core';
22
import { Router } from '@angular/router';
3-
import { CORE_DIRECTIVES, FORM_DIRECTIVES } from '@angular/common';
43
import { Http } from '@angular/http';
54
import { contentHeaders } from '../common/headers';
65

@@ -9,7 +8,6 @@ const template = require('./signup.html');
98

109
@Component({
1110
selector: 'signup',
12-
directives: [ CORE_DIRECTIVES, FORM_DIRECTIVES ],
1311
template: template,
1412
styles: [ styles ]
1513
})
@@ -24,7 +22,7 @@ export class Signup {
2422
.subscribe(
2523
response => {
2624
localStorage.setItem('id_token', response.json().id_token);
27-
this.router.navigate(['/home']);
25+
this.router.navigate(['home']);
2826
},
2927
error => {
3028
alert(error.text());
@@ -35,7 +33,7 @@ export class Signup {
3533

3634
login(event) {
3735
event.preventDefault();
38-
this.router.navigate(['/login']);
36+
this.router.navigate(['login']);
3937
}
4038

4139
}

webpack.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ module.exports = {
1313
entry: {
1414
'vendor': [
1515
// Polyfills
16-
'core-js/es6',
17-
'core-js/es7/reflect',
16+
'core-js/client/shim',
1817
'zone.js/dist/zone',
1918
'zone.js/dist/long-stack-trace-zone',
2019
// Angular2
@@ -88,7 +87,7 @@ module.exports = {
8887
/zone\.js\/dist\/.+/,
8988
/reflect-metadata/,
9089
/es(6|7)-.+/,
91-
/.zone-microtask/,
90+
/.zone-microtask/,
9291
/.long-stack-trace-zone/
9392
]
9493
},
@@ -97,13 +96,13 @@ module.exports = {
9796
new CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js', minChunks: Infinity }),
9897
new CommonsChunkPlugin({ name: 'common', filename: 'common.js', minChunks: 2, chunks: ['app', 'vendor'] })
9998
],
100-
99+
101100
// Other module loader config
102101
tslint: {
103102
emitErrors: false,
104103
failOnHint: false
105104
},
106-
105+
107106
// our Development Server configs
108107
// our Webpack Development Server config
109108
devServer: {

0 commit comments

Comments
 (0)