Skip to content

Instantly share code, notes, and snippets.

@AdonaiAraya
Created April 20, 2017 15:35
Show Gist options
  • Save AdonaiAraya/8d4b9c6a6e38220b8d10131ff451a1ec to your computer and use it in GitHub Desktop.
Save AdonaiAraya/8d4b9c6a6e38220b8d10131ff451a1ec to your computer and use it in GitHub Desktop.
Ionic basic auth decorator
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;
}
}
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