Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to alpha 29 #24

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "angular2-full-app-demo",
"name": "angular2-authentication-sample",
"version": "0.0.0",
"description": "This is a sample that shows how to add authentication to an Angular 2 (ng2) app",
"main": "",
Expand All @@ -11,17 +11,20 @@
"type": "git",
"url": "https://github.com/auth0/angular2-authentication-sample.git"
},
"author": "Martin Gontovnikas (http://gon.to) <[email protected]>",
"contributors": [
"Martin Gontovnikas (http://gon.to) <[email protected]>",
"PatrickJS <[email protected]>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/auth0/angular2-authentication-sample/issues"
},
"homepage": "https://github.com/auth0/angular2-authentication-sample",
"dependencies": {
"angular2": "2.0.0-alpha.26",
"angular2": "2.0.0-alpha.29",
"raw-loader": "^0.5.1",
"reflect-metadata": "^0.1.0",
"rtts_assert": "2.0.0-alpha.26",
"rtts_assert": "2.0.0-alpha.29",
"rx": "^2.5.3",
"zone.js": "^0.5.0",
"bootstrap": "~3.3.4",
Expand Down
16 changes: 7 additions & 9 deletions src/app/LoggedInOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ import {Router, RouterOutlet} from 'angular2/router';
import {Injector} from 'angular2/di';
import {Login} from '../login/login';

@Directive({selector: 'router-outlet'})
@Directive({
selector: 'router-outlet'
})
export class LoggedInRouterOutlet extends RouterOutlet {
publicRoutes: any
constructor(
elementRef: ElementRef,
_loader: DynamicComponentLoader,
_parentRouter: Router,
_injector: Injector,
@Attribute('name') nameAttr: string) {
constructor(public _elementRef: ElementRef, public _loader: DynamicComponentLoader,
public _parentRouter: Router, @Attribute('name') nameAttr: string) {
super(_elementRef, _loader, _parentRouter, nameAttr);

this.publicRoutes = {
'/login': true,
'/signup': true
};

super(elementRef, _loader, _parentRouter, _injector, nameAttr);
}

activate(instruction) {
var url = this._parentRouter.lastNavigationAttempt;
if (!this.publicRoutes[url] && !localStorage.getItem('jwt')) {
instruction.component = Login;
}
super.activate(instruction);
return super.activate(instruction);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you must return here otherwise you will have an error TypeError: Cannot read property 'then' of undefined

}
}
3 changes: 1 addition & 2 deletions src/app/app.html
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<router-outlet>
</router-outlet>
<router-outlet></router-outlet>
36 changes: 9 additions & 27 deletions src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// <reference path="../../typings/tsd.d.ts" />

import {View, Component} from 'angular2/angular2';
import {Location, RouteConfig, RouterLink, Router} from 'angular2/router';
import {LoggedInRouterOutlet} from './LoggedInOutlet';
import {Home} from '../home/home';
import {Login} from '../login/login';
import {Signup} from '../signup/signup';
import {RouteConfig, RouterOutlet, RouterLink, Router} from 'angular2/router';
import {BrowserLocation} from 'angular2/src/router/browser_location';
import {LoggedInRouterOutlet} from './LoggedInOutlet';

let template = require('./app.html');

Expand All @@ -15,33 +14,16 @@ let template = require('./app.html');
selector: 'auth-app'
})
@View({
template:`${template}`,
directives: [LoggedInRouterOutlet]
template: template,
directives: [ LoggedInRouterOutlet ]
})
@RouteConfig([
{ path: '/home', as: 'home', component: Home },
{ path: '/login', as: 'login', component: Login },
{ path: '/signup', as: 'signup', component: Signup }
{ path: '/', redirectTo: '/home' },
{ path: '/home', as: 'home', component: Home },
{ path: '/login', as: 'login', component: Login },
{ path: '/signup', as: 'signup', component: Signup }
])
export class App {
router: Router;
constructor(router: Router, browserLocation: BrowserLocation) {
// we need to manually go to the correct uri until the router is fixed
this.router = router;
let uri = browserLocation.path();
if (uri === '' || uri === '/') {
router.navigate('/home');
} else {
router.navigate(uri);
}
}

goTo(event, url) {
event.preventDefault();
this.router.navigate(url).then(() => {
console.log("Router successfully to", url);
}, () => {
console.log("Error going to URL", url);
});
constructor(public router: Router) {
}
}
6 changes: 0 additions & 6 deletions src/common/formInjectables.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ let template = require('./home.html');
selector: 'home'
})
@View({
template:`<style>${styles}</style>\n${template}`,
directives: [coreDirectives]
styles: [ styles ],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have styles metadata now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yey!

template: template,
directives: [ coreDirectives ]
})
export class Home {
jwt: string;
decodedJwt: string;
router: Router;
response: string;
api: string;

constructor(router: Router) {
this.router = router;
constructor(public router: Router) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use public typescript helper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to put one and one so that people can learn both.

this.jwt = localStorage.getItem('jwt');
this.decodedJwt = this.jwt && window.jwt_decode(this.jwt);
}
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/// <reference path="../typings/tsd.d.ts" />

import {routerInjectables} from 'angular2/router';
import {formInjectables} from './common/formInjectables';
import { bootstrap } from 'angular2/angular2';
import { bind } from 'angular2/di';
import { PipeRegistry } from 'angular2/change_detection';
import { routerInjectables } from 'angular2/router';
import { formInjectables } from 'angular2/forms';
import { httpInjectables } from 'angular2/http';

import { App } from './app/app';

bootstrap(
App,
[
formInjectables,
routerInjectables
routerInjectables,
httpInjectables
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending alpha.30 release with Headers fix

]
);
3 changes: 2 additions & 1 deletion src/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ let template = require('./login.html');
selector: 'login'
})
@View({
template:`<style>${styles}</style>\n${template}`,
styles: [ styles ],
template: template,
directives: [RouterLink]
})
export class Login {
Expand Down
11 changes: 4 additions & 7 deletions src/signup/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ let template = require('./signup.html');
selector: 'signup'
})
@View({
directives: [RouterLink, coreDirectives],
template:`<style>${styles}</style>\n${template}`

directives: [ RouterLink, coreDirectives ],
styles: [ styles ],
template: template
})
export class Signup {
router: Router;

constructor(router: Router) {
this.router = router;
constructor(public router: Router) {
}

signup(event, username, password) {
Expand Down
Loading