Created
April 20, 2017 15:35
-
-
Save AdonaiAraya/8d4b9c6a6e38220b8d10131ff451a1ec to your computer and use it in GitHub Desktop.
Ionic basic auth decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function Auth(data){ | |
return function (target: Function) { | |
Object.defineProperty(target.prototype, "ionViewCanEnter", { | |
value: authFunction | |
}); | |
}; | |
function authFunction(){ | |
//Here you can do your custom validation, it must return a boolean or a Promise | |
return false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component} from '@angular/core'; | |
import {IonicPage, NavController, NavParams} from 'ionic-angular'; | |
import { Auth } from "../../code/Auth"; | |
@IonicPage() | |
@Component({ | |
selector: 'page-page1', | |
templateUrl: 'page1.html', | |
}) | |
@Auth({}) | |
export class Page1 { | |
constructor(public navCtrl: NavController, public navParams: NavParams) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment