@nakedcreativity/membrs-angular-helper 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/nakedcreativity-membrs-angular-helper.umd.js +13 -1
- package/bundles/nakedcreativity-membrs-angular-helper.umd.js.map +1 -1
- package/bundles/nakedcreativity-membrs-angular-helper.umd.min.js +1 -1
- package/bundles/nakedcreativity-membrs-angular-helper.umd.min.js.map +1 -1
- package/esm2015/lib/membrs.service.js +10 -1
- package/esm2015/lib/router.config.js +6 -2
- package/fesm2015/nakedcreativity-membrs-angular-helper.js +13 -1
- package/fesm2015/nakedcreativity-membrs-angular-helper.js.map +1 -1
- package/lib/membrs.service.d.ts +4 -1
- package/nakedcreativity-membrs-angular-helper.metadata.json +1 -1
- package/package.json +1 -1
|
@@ -65,6 +65,9 @@
|
|
|
65
65
|
});
|
|
66
66
|
};
|
|
67
67
|
Object.defineProperty(MembrsService.prototype, "token", {
|
|
68
|
+
get: function () {
|
|
69
|
+
return this._token;
|
|
70
|
+
},
|
|
68
71
|
set: function (token) {
|
|
69
72
|
this._token = token;
|
|
70
73
|
localStorage.setItem(this._lsKey, token);
|
|
@@ -73,6 +76,12 @@
|
|
|
73
76
|
enumerable: false,
|
|
74
77
|
configurable: true
|
|
75
78
|
});
|
|
79
|
+
MembrsService.prototype.deleteToken = function () {
|
|
80
|
+
localStorage.removeItem(this._lsKey);
|
|
81
|
+
};
|
|
82
|
+
MembrsService.prototype.isLoggedIn = function () {
|
|
83
|
+
return this.token ? true : false;
|
|
84
|
+
};
|
|
76
85
|
Object.defineProperty(MembrsService.prototype, "profile", {
|
|
77
86
|
get: function () {
|
|
78
87
|
return this._decoded;
|
|
@@ -117,11 +126,14 @@
|
|
|
117
126
|
var transitionService = router.transitionService;
|
|
118
127
|
var stateService = router.stateService;
|
|
119
128
|
var config = injector.get(MembrsConfigService);
|
|
129
|
+
var membrsService = injector.get(MembrsService);
|
|
120
130
|
stateService.defaultErrorHandler(function (error) {
|
|
121
131
|
console.log('Default error handler - Membrs Angular Helper');
|
|
122
132
|
console.log(error);
|
|
123
|
-
if (error.detail == 'NOT_LOGGED_IN')
|
|
133
|
+
if (error.detail == 'NOT_LOGGED_IN') {
|
|
134
|
+
membrsService.deleteToken();
|
|
124
135
|
window.location.href = config.login;
|
|
136
|
+
}
|
|
125
137
|
if (error.detail == 'INSUFFICIENT_PERMISSIONS')
|
|
126
138
|
stateService.go(config.defaultState);
|
|
127
139
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nakedcreativity-membrs-angular-helper.umd.js","sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.post(this.config.apiProtocol+this.config.api+'/logout/'+this._token, {}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(error)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":["InjectionToken","JwtHelperService","Injectable","HttpClient","Inject","Transition","UIRouter","UIRouterModule","JwtModule","NgModule","CommonModule","HttpClientModule","finalize"],"mappings":";;;;;;IAGA;;;;QAIa,mBAAmB,GAAG,IAAIA,iBAAc,CAAe,cAAc;;ICFlF,IAAM,UAAU,GAAG,IAAIC,2BAAgB,EAAE,CAAA;;QAavC,uBAAoB,IAAgB,EAAuC,MAAoB;YAA3E,SAAI,GAAJ,IAAI,CAAY;YAAuC,WAAM,GAAN,MAAM,CAAc;YAF/F,WAAM,GAAW,QAAQ,CAAC;YAIxB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;;YAEjC,IAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC;gBACnC,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;aAC/C;SAEF;QAED,+BAAO,GAAP,UAAQ,KAAa;YAArB,iBAoDC;YAlDC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;gBAEjC,IAAG,CAAC,KAAK,IAAI,CAAC,KAAI,CAAC,MAAM,EAAC;oBACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;oBACpC,MAAM,CAAC,eAAe,CAAC,CAAA;iBACxB;gBAED,IAAG,KAAK;oBACN,KAAI,CAAC,KAAK,GAAG,KAAK,CAAA;;gBAGpB,IAAI,SAAS,GAAG,KAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAC,IAAI,CAAC,CAAA;;gBAG/D,IAAG,SAAS,GAAG,CAAC,EAAC;oBACf,MAAM,CAAC,eAAe,CAAC,CAAA;iBACxB;;gBAGD,IAAG,SAAS,GAAG,GAAG,EAAC;oBAEjB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;oBAGpC,OAAO,CAAC,GA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eAAe,GAAGC,sBAAc,CAAC,QAAQ,CAAC;gBAC9C,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,cAAc;aACvB,CAAC,CAAC,SAAS,CAAA;YAEZ,eAAe,CAAC,IAAI,CAACC,oBAAS,CAAC,OAAO,CAAC;gBACrC,MAAM,EAAE;oBACN,WAAW,EAAE,aAAa;oBAC1B,cAAc,EAAE,EAAE;iBACnB;aACF,CAAC,CAAC,SAAS,CAAC,CAAA;YAEb,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;YACnC,eAAe,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,mBAAmB,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;YAGtE,OAAO;gBACL,QAAQ,EAAE,YAAY;gBACtB,SAAS,EAAE,eAAe;aAC3B,CAAC;SAEH;;;;gBA7CFC,WAAQ,SAAC;oBACR,OAAO,EAAE;wBACPC,mBAAY;wBACZC,mBAAgB;wBAChBH,oBAAS;;;;;;;;;;;qBAWV;iBACF;;;;QC/FC;SAAgB;QAChB,oCAAS,GAAT,UAAU,OAAyB,EAAE,IAAiB;;YAGpD,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;gBACtB,UAAU,EAAE;oBACV,aAAa,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC;iBAC9C;aACF,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAACI,kBAAQ,CAAC;;aAEzC,CAAC,CAAC,CAAC;SACL;;;;gBAdFV,aAAU;;;;ICZX;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"nakedcreativity-membrs-angular-helper.umd.js","sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n deleteToken(){\n localStorage.removeItem(this._lsKey)\n }\n\n isLoggedIn(){\n return this.token ? true : false\n }\n\n get profile(){\n return this._decoded\n }\n\n get token(){\n return this._token\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.post(this.config.apiProtocol+this.config.api+'/logout/'+this._token, {}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(error)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\nimport { MembrsService } from './membrs.service';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n const membrsService = injector.get(MembrsService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN'){\n\t\t\tmembrsService.deleteToken()\n\t\t\twindow.location.href = config.login;\n\t\t}\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":["InjectionToken","JwtHelperService","Injectable","HttpClient","Inject","Transition","UIRouter","UIRouterModule","JwtModule","NgModule","CommonModule","HttpClientModule","finalize"],"mappings":";;;;;;IAGA;;;;QAIa,mBAAmB,GAAG,IAAIA,iBAAc,CAAe,cAAc;;ICFlF,IAAM,UAAU,GAAG,IAAIC,2BAAgB,EAAE,CAAA;;QAavC,uBAAoB,IAAgB,EAAuC,MAAoB;YAA3E,SAAI,GAAJ,IAAI,CAAY;YAAuC,WAAM,GAAN,MAAM,CAAc;YAF/F,WAAM,GAAW,QAAQ,CAAC;YAIxB,OAAO,CAAC,GAAG,CAA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AM,EAAE,MAAM;gBACd,MAAM,EAAE,cAAc;aACvB,CAAC,CAAC,SAAS,CAAA;YAEZ,eAAe,CAAC,IAAI,CAACC,oBAAS,CAAC,OAAO,CAAC;gBACrC,MAAM,EAAE;oBACN,WAAW,EAAE,aAAa;oBAC1B,cAAc,EAAE,EAAE;iBACnB;aACF,CAAC,CAAC,SAAS,CAAC,CAAA;YAEb,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;YACnC,eAAe,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,mBAAmB,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;YAGtE,OAAO;gBACL,QAAQ,EAAE,YAAY;gBACtB,SAAS,EAAE,eAAe;aAC3B,CAAC;SAEH;;;;gBA7CFC,WAAQ,SAAC;oBACR,OAAO,EAAE;wBACPC,mBAAY;wBACZC,mBAAgB;wBAChBH,oBAAS;;;;;;;;;;;qBAWV;iBACF;;;;QC/FC;SAAgB;QAChB,oCAAS,GAAT,UAAU,OAAyB,EAAE,IAAiB;;YAGpD,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;gBACtB,UAAU,EAAE;oBACV,aAAa,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC;iBAC9C;aACF,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAACI,kBAAQ,CAAC;;aAEzC,CAAC,CAAC,CAAC;SACL;;;;gBAdFV,aAAU;;;;ICZX;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("@auth0/angular-jwt"),require("@angular/common/http"),require("@angular/common"),require("@uirouter/angular"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@nakedcreativity/membrs-angular-helper",["exports","@angular/core","@auth0/angular-jwt","@angular/common/http","@angular/common","@uirouter/angular","rxjs/operators"],o):o(((e=e||self).nakedcreativity=e.nakedcreativity||{},e.nakedcreativity["membrs-angular-helper"]={}),e.ng.core,e.angularJwt,e.ng.common.http,e.ng.common,e.angular,e.rxjs.operators)}(this,(function(e,o,t,n,r,i,s){"use strict";var l=new o.InjectionToken("MembrsConfig"),a=new t.JwtHelperService,c=function(){function e(e,o){this.http=e,this.config=o,this._lsKey="membrs",console.log("membrs constructor"),localStorage.getItem(this._lsKey)&&(this.token=localStorage.getItem(this._lsKey))}return e.prototype.reissue=function(e){var o=this;return new Promise((function(t,n){e||o._token||(console.log("reject, not logged in"),n("NOT_LOGGED_IN")),e&&(o.token=e);var r=o._decoded.exp-Math.floor(Date.now()/1e3);r<0&&n("NOT_LOGGED_IN"),r<300?(console.log("expires less than 300"),console.log(o.config),o.http.post(o.config.apiProtocol+o.config.api+"/token/"+o._token,{}).subscribe((function(e){console.log("reissue response"),console.log(e),e.token?(o.token=e.token,t(o._token)):(console.log("error"),console.log(e),n("NOT_LOGGED_IN"))}),(function(e){console.log(e),n("NOT_LOGGED_IN")}))):(console.log("token ok"),t(o._token))}))},Object.defineProperty(e.prototype,"token",{set:function(e){this._token=e,localStorage.setItem(this._lsKey,e),this._decoded=a.decodeToken(this._token)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"profile",{get:function(){return this._decoded},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"admin",{get:function(){return 1==this.profile.permission},enumerable:!1,configurable:!0}),e.prototype.logout=function(){var e=this;return new Promise((function(o,t){e.http.post(e.config.apiProtocol+e.config.api+"/logout/"+e._token,{}).subscribe((function(t){e._token=null,localStorage.removeItem(e._lsKey),o(e.config.login)}),(function(e){t(e)}))}))},e}();function u(e,o){e.transitionService;var t=e.stateService,n=o.get(l);t.defaultErrorHandler((function(e){console.log("Default error handler - Membrs Angular Helper"),console.log(e),"NOT_LOGGED_IN"==e.detail&&(window.location.href=n.login),"INSUFFICIENT_PERMISSIONS"==e.detail&&t.go(n.defaultState)}))}function g(){return console.log("retrieve from ls"),localStorage.getItem("membrs")}c.ɵprov=o.ɵɵdefineInjectable({factory:function(){return new c(o.ɵɵinject(n.HttpClient),o.ɵɵinject(l))},token:c,providedIn:"root"}),c.decorators=[{type:o.Injectable,args:[{providedIn:"root"}]}],c.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:o.Inject,args:[l]}]}]};var f={token:"reissue",deps:[i.Transition,i.UIRouter,c,l],resolveFn:v},p={token:"reissue",deps:[i.Transition,i.UIRouter,c,l],resolveFn:m},d={name:"reissue",url:"/reissue?token",views:{},resolve:[p]};function m(e,o,t,n){return new Promise((function(r,i){console.log("reissue promise resolve"),console.log(e.params().token),t.reissue(e.params().token).then((function(e){console.log("redirect to default state"),o.stateService.go(n.defaultState,{},{inherit:!1}),i()})).catch((function(e){console.log("error in reissue resolve"),console.log(e),i(e)}))}))}function v(e,o,t,n){return new Promise((function(e,o){console.log("validate promise resolve"),t.reissue().then((function(o){e()})).catch((function(e){console.log("error in validateResolveFn"),console.log(e),o(e)}))}))}var h=[d],k=function(){function e(){}return e.forRoot=function(o){var n=i.UIRouterModule.forChild({states:h,config:u}).providers;return n.push(t.JwtModule.forRoot({config:{tokenGetter:g,allowedDomains:[]}}).providers),n.push(c),n.push({provide:l,useValue:o}),{ngModule:e,providers:n}},e}();k.decorators=[{type:o.NgModule,args:[{imports:[r.CommonModule,n.HttpClientModule,t.JwtModule]}]}];var y=function(){function e(){}return e.prototype.intercept=function(e,o){return e=e.clone({setHeaders:{Authorization:localStorage.getItem("membrs")}}),o.handle(e).pipe(s.finalize((function(){})))},e}();y.decorators=[{type:o.Injectable}],y.ctorParameters=function(){return[]},e.MembrsModule=k,e.MembrsService=c,e.STATES=h,e.TokenInterceptor=y,e.jwtOptionsFactory=function(e){return console.log("jwt options factory"),console.log(e),{tokenGetter:function(){return console.log("token getter",localStorage.getItem("membrs")),localStorage.getItem("membrs")},allowedDomains:[e.api]}},e.reissueResolve=p,e.reissueResolveFn=m,e.reissueState=d,e.retrieveToken=g,e.validateResolve=f,e.validateResolveFn=v,e.ɵa=l,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("@auth0/angular-jwt"),require("@angular/common/http"),require("@angular/common"),require("@uirouter/angular"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@nakedcreativity/membrs-angular-helper",["exports","@angular/core","@auth0/angular-jwt","@angular/common/http","@angular/common","@uirouter/angular","rxjs/operators"],o):o(((e=e||self).nakedcreativity=e.nakedcreativity||{},e.nakedcreativity["membrs-angular-helper"]={}),e.ng.core,e.angularJwt,e.ng.common.http,e.ng.common,e.angular,e.rxjs.operators)}(this,(function(e,o,t,n,r,i,s){"use strict";var l=new o.InjectionToken("MembrsConfig"),a=new t.JwtHelperService,c=function(){function e(e,o){this.http=e,this.config=o,this._lsKey="membrs",console.log("membrs constructor"),localStorage.getItem(this._lsKey)&&(this.token=localStorage.getItem(this._lsKey))}return e.prototype.reissue=function(e){var o=this;return new Promise((function(t,n){e||o._token||(console.log("reject, not logged in"),n("NOT_LOGGED_IN")),e&&(o.token=e);var r=o._decoded.exp-Math.floor(Date.now()/1e3);r<0&&n("NOT_LOGGED_IN"),r<300?(console.log("expires less than 300"),console.log(o.config),o.http.post(o.config.apiProtocol+o.config.api+"/token/"+o._token,{}).subscribe((function(e){console.log("reissue response"),console.log(e),e.token?(o.token=e.token,t(o._token)):(console.log("error"),console.log(e),n("NOT_LOGGED_IN"))}),(function(e){console.log(e),n("NOT_LOGGED_IN")}))):(console.log("token ok"),t(o._token))}))},Object.defineProperty(e.prototype,"token",{get:function(){return this._token},set:function(e){this._token=e,localStorage.setItem(this._lsKey,e),this._decoded=a.decodeToken(this._token)},enumerable:!1,configurable:!0}),e.prototype.deleteToken=function(){localStorage.removeItem(this._lsKey)},e.prototype.isLoggedIn=function(){return!!this.token},Object.defineProperty(e.prototype,"profile",{get:function(){return this._decoded},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"admin",{get:function(){return 1==this.profile.permission},enumerable:!1,configurable:!0}),e.prototype.logout=function(){var e=this;return new Promise((function(o,t){e.http.post(e.config.apiProtocol+e.config.api+"/logout/"+e._token,{}).subscribe((function(t){e._token=null,localStorage.removeItem(e._lsKey),o(e.config.login)}),(function(e){t(e)}))}))},e}();function u(e,o){e.transitionService;var t=e.stateService,n=o.get(l),r=o.get(c);t.defaultErrorHandler((function(e){console.log("Default error handler - Membrs Angular Helper"),console.log(e),"NOT_LOGGED_IN"==e.detail&&(r.deleteToken(),window.location.href=n.login),"INSUFFICIENT_PERMISSIONS"==e.detail&&t.go(n.defaultState)}))}function g(){return console.log("retrieve from ls"),localStorage.getItem("membrs")}c.ɵprov=o.ɵɵdefineInjectable({factory:function(){return new c(o.ɵɵinject(n.HttpClient),o.ɵɵinject(l))},token:c,providedIn:"root"}),c.decorators=[{type:o.Injectable,args:[{providedIn:"root"}]}],c.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:o.Inject,args:[l]}]}]};var f={token:"reissue",deps:[i.Transition,i.UIRouter,c,l],resolveFn:v},p={token:"reissue",deps:[i.Transition,i.UIRouter,c,l],resolveFn:m},d={name:"reissue",url:"/reissue?token",views:{},resolve:[p]};function m(e,o,t,n){return new Promise((function(r,i){console.log("reissue promise resolve"),console.log(e.params().token),t.reissue(e.params().token).then((function(e){console.log("redirect to default state"),o.stateService.go(n.defaultState,{},{inherit:!1}),i()})).catch((function(e){console.log("error in reissue resolve"),console.log(e),i(e)}))}))}function v(e,o,t,n){return new Promise((function(e,o){console.log("validate promise resolve"),t.reissue().then((function(o){e()})).catch((function(e){console.log("error in validateResolveFn"),console.log(e),o(e)}))}))}var h=[d],k=function(){function e(){}return e.forRoot=function(o){var n=i.UIRouterModule.forChild({states:h,config:u}).providers;return n.push(t.JwtModule.forRoot({config:{tokenGetter:g,allowedDomains:[]}}).providers),n.push(c),n.push({provide:l,useValue:o}),{ngModule:e,providers:n}},e}();k.decorators=[{type:o.NgModule,args:[{imports:[r.CommonModule,n.HttpClientModule,t.JwtModule]}]}];var y=function(){function e(){}return e.prototype.intercept=function(e,o){return e=e.clone({setHeaders:{Authorization:localStorage.getItem("membrs")}}),o.handle(e).pipe(s.finalize((function(){})))},e}();y.decorators=[{type:o.Injectable}],y.ctorParameters=function(){return[]},e.MembrsModule=k,e.MembrsService=c,e.STATES=h,e.TokenInterceptor=y,e.jwtOptionsFactory=function(e){return console.log("jwt options factory"),console.log(e),{tokenGetter:function(){return console.log("token getter",localStorage.getItem("membrs")),localStorage.getItem("membrs")},allowedDomains:[e.api]}},e.reissueResolve=p,e.reissueResolveFn=m,e.reissueState=d,e.retrieveToken=g,e.validateResolve=f,e.validateResolveFn=v,e.ɵa=l,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=nakedcreativity-membrs-angular-helper.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts"],"names":["MembrsConfigService","InjectionToken","jwtService","JwtHelperService","MembrsService","http","config","this","_lsKey","console","log","localStorage","getItem","token","prototype","reissue","_this","Promise","resolve","reject","_token","reissueIn","_decoded","exp","Math","floor","Date","now","post","apiProtocol","api","subscribe","response","error","Object","defineProperty","setItem","decodeToken","profile","permission","logout","removeItem","login","routerConfigFn","router","injector","transitionService","stateService","get","defaultErrorHandler","detail","window","location","href","go","defaultState","retrieveToken","Injectable","args","providedIn","HttpClient","Inject","validateResolve","deps","Transition","UIRouter","resolveFn","validateResolveFn","reissueResolve","reissueResolveFn","reissueState","name","url","views","transition","membrsService","membrsConfig","params","then","inherit","catch","STATES","MembrsModule","forRoot","moduleProviders","UIRouterModule","forChild","states","providers","push","JwtModule","tokenGetter","allowedDomains","provide","useValue","ngModule","NgModule","imports","CommonModule","HttpClientModule","TokenInterceptor","intercept","request","next","clone","setHeaders","Authorization","handle","pipe","finalize"],"mappings":"orBAOaA,EAAsB,IAAIC,EAAAA,eAA6B,gBCF9DC,EAAa,IAAIC,EAAAA,8BAarB,SAAAC,EAAoBC,EAAuDC,GAAvDC,KAAAF,KAAAA,EAAuDE,KAAAD,OAAAA,EAF3EC,KAAAC,OAAiB,SAIfC,QAAQC,IAAI,sBAETC,aAAaC,QAAQL,KAAKC,UAC3BD,KAAKM,MAAQF,aAAaC,QAAQL,KAAKC,gBAK3CJ,EAAAU,UAAAC,QAAA,SAAQF,GAAR,IAAAG,EAAAT,KAEE,OAAO,IAAIU,SAAQ,SAACC,EAASC,GAEvBN,GAAUG,EAAKI,SACjBX,QAAQC,IAAI,yBACZS,EAAO,kBAGNN,IACDG,EAAKH,MAAQA,GAGf,IAAIQ,EAAYL,EAAKM,SAASC,IAAMC,KAAKC,MAAMC,KAAKC,MAAM,KAGvDN,EAAY,GACbF,EAAO,iBAINE,EAAY,KAEbZ,QAAQC,IAAI,yBAGZD,QAAQC,IAAIM,EAAKV,QAEjBU,EAAKX,KAAKuB,KAAKZ,EAAKV,OAAOuB,YAAcb,EAAKV,OAAOwB,IAAI,UAAUd,EAAKI,OAAQ,IAAIW,WAAU,SAACC,GAC7FvB,QAAQC,IAAI,oBACZD,QAAQC,IAAIsB,GACTA,EAASnB,OACVG,EAAKH,MAAQmB,EAASnB,MACtBK,EAAQF,EAAKI,UAEbX,QAAQC,IAAI,SACZD,QAAQC,IAAIsB,GACZb,EAAO,qBAGR,SAAAc,GACDxB,QAAQC,IAAIuB,GACZd,EAAO,sBAITV,QAAQC,IAAI,YACZQ,EAAQF,EAAKI,aAOnBc,OAAAC,eAAI/B,EAAAU,UAAA,QAAK,KAAT,SAAUD,GACRN,KAAKa,OAASP,EACdF,aAAayB,QAAQ7B,KAAKC,OAAQK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cAAe/F,aAAaC,QAAQ,aAGjC2F,EAAKI,OAAOL,GAASM,KAAKC,EAAAA,UAAS,0CAX7CpD,EAAAA,mJD8DiCnD,GAGhC,OAFAG,QAAQC,IAAI,uBACZD,QAAQC,IAAIJ,GACL,CACLqF,YAAa,WAEX,OADAlF,QAAQC,IAAI,eAAiBC,aAAaC,QAAQ,WAC3CD,aAAaC,QAAQ,WAE9BgF,eAAgB,CAACtF,EAAOwB","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.post(this.config.apiProtocol+this.config.api+'/logout/'+this._token, {}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(error)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts"],"names":["MembrsConfigService","InjectionToken","jwtService","JwtHelperService","MembrsService","http","config","this","_lsKey","console","log","localStorage","getItem","token","prototype","reissue","_this","Promise","resolve","reject","_token","reissueIn","_decoded","exp","Math","floor","Date","now","post","apiProtocol","api","subscribe","response","error","Object","defineProperty","setItem","decodeToken","deleteToken","removeItem","isLoggedIn","profile","permission","logout","login","routerConfigFn","router","injector","transitionService","stateService","get","membrsService","defaultErrorHandler","detail","window","location","href","go","defaultState","retrieveToken","Injectable","args","providedIn","HttpClient","Inject","validateResolve","deps","Transition","UIRouter","resolveFn","validateResolveFn","reissueResolve","reissueResolveFn","reissueState","name","url","views","transition","membrsConfig","params","then","inherit","catch","STATES","MembrsModule","forRoot","moduleProviders","UIRouterModule","forChild","states","providers","push","JwtModule","tokenGetter","allowedDomains","provide","useValue","ngModule","NgModule","imports","CommonModule","HttpClientModule","TokenInterceptor","intercept","request","next","clone","setHeaders","Authorization","handle","pipe","finalize"],"mappings":"orBAOaA,EAAsB,IAAIC,EAAAA,eAA6B,gBCF9DC,EAAa,IAAIC,EAAAA,8BAarB,SAAAC,EAAoBC,EAAuDC,GAAvDC,KAAAF,KAAAA,EAAuDE,KAAAD,OAAAA,EAF3EC,KAAAC,OAAiB,SAIfC,QAAQC,IAAI,sBAETC,aAAaC,QAAQL,KAAKC,UAC3BD,KAAKM,MAAQF,aAAaC,QAAQL,KAAKC,gBAK3CJ,EAAAU,UAAAC,QAAA,SAAQF,GAAR,IAAAG,EAAAT,KAEE,OAAO,IAAIU,SAAQ,SAACC,EAASC,GAEvBN,GAAUG,EAAKI,SACjBX,QAAQC,IAAI,yBACZS,EAAO,kBAGNN,IACDG,EAAKH,MAAQA,GAGf,IAAIQ,EAAYL,EAAKM,SAASC,IAAMC,KAAKC,MAAMC,KAAKC,MAAM,KAGvDN,EAAY,GACbF,EAAO,iBAINE,EAAY,KAEbZ,QAAQC,IAAI,yBAGZD,QAAQC,IAAIM,EAAKV,QAEjBU,EAAKX,KAAKuB,KAAKZ,EAAKV,OAAOuB,YAAcb,EAAKV,OAAOwB,IAAI,UAAUd,EAAKI,OAAQ,IAAIW,WAAU,SAACC,GAC7FvB,QAAQC,IAAI,oBACZD,QAAQC,IAAIsB,GACTA,EAASnB,OACVG,EAAKH,MAAQmB,EAASnB,MACtBK,EAAQF,EAAKI,UAEbX,QAAQC,IAAI,SACZD,QAAQC,IAAIsB,GACZb,E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A,UAAUP,QAAQ,CACrC/E,OAAQ,CACNuF,YAAalC,EACbmC,eAAgB,MAEjBJ,WAEHJ,EAAgBK,KAAKvF,GACrBkF,EAAgBK,KAAK,CAACI,QAAS/F,EAAoBgG,SAAU1F,IAGtD,CACL2F,SAAUb,EACVM,UAAWJ,6BA1ChBY,EAAAA,SAAQrC,KAAA,CAAC,CACRsC,QAAS,CACPC,EAAAA,aACAC,EAAAA,iBACAT,EAAAA,gCCnFF,SAAAU,YACAA,EAAAxF,UAAAyF,UAAA,SAAUC,EAA2BC,GAQnC,OALAD,EAAUA,EAAQE,MAAM,CACtBC,WAAY,CACVC,cAAejG,aAAaC,QAAQ,aAGjC6F,EAAKI,OAAOL,GAASM,KAAKC,EAAAA,UAAS,0CAX7CnD,EAAAA,mJD8DiCtD,GAGhC,OAFAG,QAAQC,IAAI,uBACZD,QAAQC,IAAIJ,GACL,CACLuF,YAAa,WAEX,OADApF,QAAQC,IAAI,eAAiBC,aAAaC,QAAQ,WAC3CD,aAAaC,QAAQ,WAE9BkF,eAAgB,CAACxF,EAAOwB","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n deleteToken(){\n localStorage.removeItem(this._lsKey)\n }\n\n isLoggedIn(){\n return this.token ? true : false\n }\n\n get profile(){\n return this._decoded\n }\n\n get token(){\n return this._token\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.post(this.config.apiProtocol+this.config.api+'/logout/'+this._token, {}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(error)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\nimport { MembrsService } from './membrs.service';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n const membrsService = injector.get(MembrsService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN'){\n\t\t\tmembrsService.deleteToken()\n\t\t\twindow.location.href = config.login;\n\t\t}\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}"]}
|
|
@@ -63,9 +63,18 @@ export class MembrsService {
|
|
|
63
63
|
localStorage.setItem(this._lsKey, token);
|
|
64
64
|
this._decoded = jwtService.decodeToken(this._token);
|
|
65
65
|
}
|
|
66
|
+
deleteToken() {
|
|
67
|
+
localStorage.removeItem(this._lsKey);
|
|
68
|
+
}
|
|
69
|
+
isLoggedIn() {
|
|
70
|
+
return this.token ? true : false;
|
|
71
|
+
}
|
|
66
72
|
get profile() {
|
|
67
73
|
return this._decoded;
|
|
68
74
|
}
|
|
75
|
+
get token() {
|
|
76
|
+
return this._token;
|
|
77
|
+
}
|
|
69
78
|
get admin() {
|
|
70
79
|
return this.profile.permission == 1;
|
|
71
80
|
}
|
|
@@ -92,4 +101,4 @@ MembrsService.ctorParameters = () => [
|
|
|
92
101
|
{ type: HttpClient },
|
|
93
102
|
{ type: undefined, decorators: [{ type: Inject, args: [MembrsConfigService,] }] }
|
|
94
103
|
];
|
|
95
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
104
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtYnJzLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9tZW1icnMvc3JjL2xpYi9tZW1icnMuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUNuRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sc0JBQXNCLENBQUE7QUFDakQsT0FBTyxFQ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KHRva2VuKVxuICAgICAgICB0aGlzLnRva2VuID0gdG9rZW5cblxuICAgICAgLy8gY2hlY2sgc3RvcmVkIHRva2VuIGhhcyBub3QgZXhwaXJlZCwgb3IgbmVlZHMgdG8gYmUgcmVpc3N1ZWQgc29vblxuICAgICAgdmFyIHJlaXNzdWVJbiA9IHRoaXMuX2RlY29kZWQuZXhwIC0gTWF0aC5mbG9vcihEYXRlLm5vdygpLzEwMDApXG4gICAgXG4gICAgICAvLyB0b2tlbiBoYXMgZXhwaXJlZFxuICAgICAgaWYocmVpc3N1ZUluIDwgMCl7XG4gICAgICAgIHJlamVjdCgnTk9UX0xPR0dFRF9JTicpXG4gICAgICB9XG4gICAgICBcbiAgICAgIC8vIHRva2VuIGV4cGlyaW5nIHNvb25cbiAgICAgIGlmKHJlaXNzdWVJbiA8IDMwMCl7XG4gICAgICAgIFxuICAgICAgICBjb25zb2xlLmxvZygnZXhwaXJlcyBsZXNzIHRoYW4gMzAwJylcbiAgICAgICAgXG4gICAgICAgIFxuICAgICAgICBjb25zb2xlLmxvZyh0aGlzLmNvbmZpZylcblxuICAgICAgICB0aGlzLmh0dHAucG9zdCh0aGlzLmNvbmZpZy5hcGlQcm90b2NvbCArIHRoaXMuY29uZmlnLmFwaSsnL3Rva2VuLycrdGhpcy5fdG9rZW4sIHt9KS5zdWJzY3JpYmUoKHJlc3BvbnNlOmFueSk9PntcbiAgICAgICAgICBjb25zb2xlLmxvZygncmVpc3N1ZSByZXNwb25zZScpXG4gICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2UpXG4gICAgICAgICAgaWYocmVzcG9uc2UudG9rZW4pe1xuICAgICAgICAgICAgdGhpcy50b2tlbiA9IHJlc3BvbnNlLnRva2VuXG4gICAgICAgICAgICByZXNvbHZlKHRoaXMuX3Rva2VuKVxuICAgICAgICAgIH1lbHNlIHtcbiAgICAgICAgICAgIGNvbnNvbGUubG9nKCdlcnJvcicpXG4gICAgICAgICAgICBjb25zb2xlLmxvZyhyZXN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cm90b2NvbCt0aGlzLmNvbmZpZy5hcGkrJy9sb2dvdXQvJyt0aGlzLl90b2tlbiwge30pLnN1YnNjcmliZSgocmVzcG9uc2U6YW55KT0+e1xuICAgICAgICB0aGlzLl90b2tlbiA9IG51bGw7XG4gICAgICAgIGxvY2FsU3RvcmFnZS5yZW1vdmVJdGVtKHRoaXMuX2xzS2V5KVxuICAgICAgICByZXNvbHZlKHRoaXMuY29uZmlnLmxvZ2luKVxuICAgICAgICAvL3RoaXMucm91dGVyLnN0YXRlU2VydmljZS5nbygnZGFzaGJvYXJkJylcbiAgICAgIH0sIGVycm9yPT57XG4gICAgICAgIHJlamVjdChlcnJvcilcbiAgICAgIH0pXG4gICAgfSlcbiAgICBcbiAgfVxuXG5cbn1cbiJdfQ==
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { MembrsConfigService } from './config.service';
|
|
2
|
+
import { MembrsService } from './membrs.service';
|
|
2
3
|
export function routerConfigFn(router, injector) {
|
|
3
4
|
const transitionService = router.transitionService;
|
|
4
5
|
const stateService = router.stateService;
|
|
5
6
|
const config = injector.get(MembrsConfigService);
|
|
7
|
+
const membrsService = injector.get(MembrsService);
|
|
6
8
|
stateService.defaultErrorHandler(function (error) {
|
|
7
9
|
console.log('Default error handler - Membrs Angular Helper');
|
|
8
10
|
console.log(error);
|
|
9
|
-
if (error.detail == 'NOT_LOGGED_IN')
|
|
11
|
+
if (error.detail == 'NOT_LOGGED_IN') {
|
|
12
|
+
membrsService.deleteToken();
|
|
10
13
|
window.location.href = config.login;
|
|
14
|
+
}
|
|
11
15
|
if (error.detail == 'INSUFFICIENT_PERMISSIONS')
|
|
12
16
|
stateService.go(config.defaultState);
|
|
13
17
|
});
|
|
14
18
|
}
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiL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R3aW5kb3cubG9jYXRpb24uaHJlZiA9IGNvbmZpZy5sb2dpbjtcblx0XHR9XG5cblx0XHRpZihlcnJvci5kZXRhaWwgPT0gJ0lOU1VGRklDSUVOVF9QRVJNSVNTSU9OUycpXG5cdFx0XHRzdGF0ZVNlcnZpY2UuZ28oY29uZmlnLmRlZmF1bHRTdGF0ZSlcblxuXHR9KTtcblx0XG59Il19
|
|
@@ -69,9 +69,18 @@ class MembrsService {
|
|
|
69
69
|
localStorage.setItem(this._lsKey, token);
|
|
70
70
|
this._decoded = jwtService.decodeToken(this._token);
|
|
71
71
|
}
|
|
72
|
+
deleteToken() {
|
|
73
|
+
localStorage.removeItem(this._lsKey);
|
|
74
|
+
}
|
|
75
|
+
isLoggedIn() {
|
|
76
|
+
return this.token ? true : false;
|
|
77
|
+
}
|
|
72
78
|
get profile() {
|
|
73
79
|
return this._decoded;
|
|
74
80
|
}
|
|
81
|
+
get token() {
|
|
82
|
+
return this._token;
|
|
83
|
+
}
|
|
75
84
|
get admin() {
|
|
76
85
|
return this.profile.permission == 1;
|
|
77
86
|
}
|
|
@@ -103,11 +112,14 @@ function routerConfigFn(router, injector) {
|
|
|
103
112
|
const transitionService = router.transitionService;
|
|
104
113
|
const stateService = router.stateService;
|
|
105
114
|
const config = injector.get(MembrsConfigService);
|
|
115
|
+
const membrsService = injector.get(MembrsService);
|
|
106
116
|
stateService.defaultErrorHandler(function (error) {
|
|
107
117
|
console.log('Default error handler - Membrs Angular Helper');
|
|
108
118
|
console.log(error);
|
|
109
|
-
if (error.detail == 'NOT_LOGGED_IN')
|
|
119
|
+
if (error.detail == 'NOT_LOGGED_IN') {
|
|
120
|
+
membrsService.deleteToken();
|
|
110
121
|
window.location.href = config.login;
|
|
122
|
+
}
|
|
111
123
|
if (error.detail == 'INSUFFICIENT_PERMISSIONS')
|
|
112
124
|
stateService.go(config.defaultState);
|
|
113
125
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nakedcreativity-membrs-angular-helper.js","sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n get profile(){\n return this._decoded\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.post(this.config.apiProtocol+this.config.api+'/logout/'+this._token, {}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(error)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN')\n\t\t\twindow.location.href = config.login;\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":[],"mappings":";;;;;;;AAGA;;;;MAIa,mBAAmB,GAAG,IAAI,cAAc,CAAe,cAAc;;ACFlF,MAAM,UAAU,GAAG,IAAI,gBAAgB,EAAE,CAAA;MAO5B,aAAa;IAMxB,YAAoB,IAAgB,EAAuC,MAAoB;QAA3E,SAAI,GAAJ,IAAI,CAAY;QAAuC,WAAM,GAAN,MAAM,CAAc;QAF/F,WAAM,GAAW,QAAQ,CAAC;QAIxB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;;QAEjC,IAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM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,iBAAgB;IAChB,SAAS,CAAC,OAAyB,EAAE,IAAiB;;QAGpD,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;YACtB,UAAU,EAAE;gBACV,aAAa,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC;aAC9C;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;;SAEzC,CAAC,CAAC,CAAC;KACL;;;YAdF,UAAU;;;;ACZX;;;;;;"}
|
|
1
|
+
{"version":3,"file":"nakedcreativity-membrs-angular-helper.js","sources":["../../../projects/membrs/src/lib/config.service.ts","../../../projects/membrs/src/lib/membrs.service.ts","../../../projects/membrs/src/lib/router.config.ts","../../../projects/membrs/src/lib/token.ts","../../../projects/membrs/src/lib/membrs.module.ts","../../../projects/membrs/src/lib/auth.interceptor.ts","../../../projects/membrs/src/nakedcreativity-membrs-angular-helper.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { MembrsConfig } from './config.interface';\n\n/**\n * This is not a real service, but it looks like it from the outside.\n * It's just an InjectionTToken used to import the config object, provided from the outside\n */\nexport const MembrsConfigService = new InjectionToken<MembrsConfig>(\"MembrsConfig\");\n","import { Injectable, Inject } from '@angular/core';\nimport { JwtHelperService } from '@auth0/angular-jwt';\nimport { HttpClient } from '@angular/common/http'\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nconst jwtService = new JwtHelperService()\n\n@Injectable({\n providedIn: 'root'\n})\n\n\nexport class MembrsService {\n\n _token: string;\n _decoded: any;\n _lsKey: string = 'membrs';\n\n constructor(private http: HttpClient, @Inject(MembrsConfigService) private config: MembrsConfig) {\n\n console.log('membrs constructor')\n // if the token exists in local storage, retrieve it back to the service\n if(localStorage.getItem(this._lsKey)){\n this.token = localStorage.getItem(this._lsKey)\n }\n \n }\n\n reissue(token?:string){\n\n return new Promise((resolve, reject)=>{\n\n if(!token && !this._token){\n console.log('reject, not logged in')\n reject('NOT_LOGGED_IN')\n }\n\n if(token)\n this.token = token\n\n // check stored token has not expired, or needs to be reissued soon\n var reissueIn = this._decoded.exp - Math.floor(Date.now()/1000)\n \n // token has expired\n if(reissueIn < 0){\n reject('NOT_LOGGED_IN')\n }\n \n // token expiring soon\n if(reissueIn < 300){\n \n console.log('expires less than 300')\n \n \n console.log(this.config)\n\n this.http.post(this.config.apiProtocol + this.config.api+'/token/'+this._token, {}).subscribe((response:any)=>{\n console.log('reissue response')\n console.log(response)\n if(response.token){\n this.token = response.token\n resolve(this._token)\n }else {\n console.log('error')\n console.log(response)\n reject('NOT_LOGGED_IN')\n }\n \n }, error=>{\n console.log(error)\n reject('NOT_LOGGED_IN')\n })\n\n }else {\n console.log('token ok')\n resolve(this._token)\n }\n \n })\n \n }\n\n set token(token){\n this._token = token\n localStorage.setItem(this._lsKey, token)\n this._decoded = jwtService.decodeToken(this._token)\n }\n\n deleteToken(){\n localStorage.removeItem(this._lsKey)\n }\n\n isLoggedIn(){\n return this.token ? true : false\n }\n\n get profile(){\n return this._decoded\n }\n\n get token(){\n return this._token\n }\n\n get admin (){\n return this.profile.permission == 1\n }\n\n logout(){\n return new Promise((resolve, reject)=>{\n this.http.post(this.config.apiProtocol+this.config.api+'/logout/'+this._token, {}).subscribe((response:any)=>{\n this._token = null;\n localStorage.removeItem(this._lsKey)\n resolve(this.config.login)\n //this.router.stateService.go('dashboard')\n }, error=>{\n reject(error)\n })\n })\n \n }\n\n\n}\n","import { UIRouter } from '@uirouter/core';\nimport { MembrsConfigService } from './config.service'\nimport { MembrsConfig } from './config.interface';\nimport { Injector } from '@angular/core';\nimport { MembrsService } from './membrs.service';\n\nexport function routerConfigFn(router: UIRouter, injector: Injector) {\n\n const transitionService = router.transitionService;\n const stateService = router.stateService\n const config:MembrsConfig = injector.get(MembrsConfigService)\n const membrsService = injector.get(MembrsService)\n\n \tstateService.defaultErrorHandler(function(error) {\n\t\t \n\t\tconsole.log('Default error handler - Membrs Angular Helper')\n\t\tconsole.log(error)\n\t\t\t\n\t\tif(error.detail == 'NOT_LOGGED_IN'){\n\t\t\tmembrsService.deleteToken()\n\t\t\twindow.location.href = config.login;\n\t\t}\n\n\t\tif(error.detail == 'INSUFFICIENT_PERMISSIONS')\n\t\t\tstateService.go(config.defaultState)\n\n\t});\n\t\n}","export function retrieveToken() {\n console.log('retrieve from ls')\n return localStorage.getItem('membrs');\n}","import { NgModule, ModuleWithProviders, Injector } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { MembrsService } from './membrs.service';\nimport { JwtModule, JWT_OPTIONS } from \"@auth0/angular-jwt\";\nimport { HttpClientModule } from \"@angular/common/http\";\nimport { UIRouterModule } from '@uirouter/angular'\n\nimport { Ng2StateDeclaration } from '@uirouter/angular';\nimport { Transition, UIRouter } from '@uirouter/angular'\n\nimport { routerConfigFn } from './router.config';\nimport { MembrsConfig } from './config.interface';\nimport { MembrsConfigService } from './config.service';\nimport { retrieveToken } from './token';\n\nexport const validateResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: validateResolveFn\n}\n\nexport const reissueResolve = {\n token: 'reissue',\n deps: [ Transition, UIRouter, MembrsService, MembrsConfigService ],\n resolveFn: reissueResolveFn\n}\n\nexport const reissueState:Ng2StateDeclaration = {\n\tname: 'reissue', \n\turl: '/reissue?token',\n\tviews: { },\n\tresolve: [\n reissueResolve\n\t]\n}\n\nexport function reissueResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('reissue promise resolve')\n console.log(transition.params().token)\n membrsService.reissue(transition.params().token).then((response)=>{\n console.log('redirect to default state')\n router.stateService.go(membrsConfig.defaultState, {}, {inherit:false})\n reject()\n }).catch(error=>{\n console.log('error in reissue resolve')\n console.log(error)\n //window.location.href = environment.login\n reject(error)\n })\n\n\t})\n}\n\nexport function validateResolveFn(transition, router, membrsService, membrsConfig:MembrsConfig) {\n \n //console.log(membrsService)\n return new Promise((resolve, reject) => {\n console.log('validate promise resolve')\n \n membrsService.reissue().then((response)=>{\n resolve()\n }).catch(error=>{\n console.log('error in validateResolveFn')\n console.log(error)\n //window.location.href = membrsConfig.login\n reject(error)\n })\n\n})\n}\n\nexport function jwtOptionsFactory(config) {\n console.log('jwt options factory')\n console.log(config)\n return {\n tokenGetter: () => {\n console.log('token getter', localStorage.getItem('membrs'))\n return localStorage.getItem('membrs');\n },\n allowedDomains: [config.api]\n }\n}\n\n\n/** The top level state(s) */\nexport const STATES = [\n reissueState\n]\n\n\n@NgModule({\n imports: [\n CommonModule,\n HttpClientModule,\n JwtModule\n // JwtModule.forRoot({\n // config: {\n // tokenGetter: retrieveToken\n // }\n // })\n // UIRouterModule.forChild({\n // states: STATES,\n // config: routerConfigFn,\n // }),\n // JwtModule.forRoot({})\n ]\n})\n\n\n\nexport class MembrsModule { \n static forRoot(config: MembrsConfig): ModuleWithProviders<MembrsModule> {\n\n\n const moduleProviders = UIRouterModule.forChild({\n states: STATES,\n config: routerConfigFn\n }).providers\n\n moduleProviders.push(JwtModule.forRoot({\n config: {\n tokenGetter: retrieveToken,\n allowedDomains: []\n }\n }).providers)\n \n moduleProviders.push(MembrsService)\n moduleProviders.push({provide: MembrsConfigService,useValue: config});\n \n \n return {\n ngModule: MembrsModule, \n providers: moduleProviders //[{provide: MembrsConfigService,useValue: config}]\n };\n \n }\n\n}\n","import { Injectable } from '@angular/core';\nimport {\n HttpRequest,\n HttpHandler,\n HttpEvent,\n HttpInterceptor\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n//import { NgBusyService } from '@nakedcreativity/ng-busy';\nimport { finalize } from 'rxjs/operators';\n\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n constructor() {}\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n \n //this.busyService.busy()\n request = request.clone({\n setHeaders: {\n Authorization: localStorage.getItem('membrs')\n }\n });\n return next.handle(request).pipe(finalize(()=>{\n //this.busyService.finished()\n }));\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {MembrsConfig as ɵb} from './lib/config.interface';\nexport {MembrsConfigService as ɵa} from './lib/config.service';"],"names":[],"mappings":";;;;;;;AAGA;;;;MAIa,mBAAmB,GAAG,IAAI,cAAc,CAAe,cAAc;;ACFlF,MAAM,UAAU,GAAG,IAAI,gBAAgB,EAAE,CAAA;MAO5B,aAAa;IAMxB,YAAoB,IAAgB,EAAuC,MAAoB;QAA3E,SAAI,GAAJ,IAAI,CAAY;QAAuC,WAAM,GAAN,MAAM,CAAc;QAF/F,WAAM,GAAW,QAAQ,CAAC;QAIxB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;;QAEjC,IAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC;YACnC,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;SAC/C;KAEF;IAED,OAAO,CAAC,KAAa;QAEnB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM;YAEjC,IAAG,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;gBACpC,MAAM,CAAC,eAAe,CAAC,CAAA;aACxB;YAED,IAAG,KAAK;gBACN,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;;YAGpB,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAC,IAAI,CAAC,CAAA;;YAG/D,IAAG,SAAS,GAAG,CAAC,EAAC;gBACf,MAAM,CAAC,eAAe,CAAC,CAAA;aACxB;;YAGD,IAAG,SAAS,GAAG,GAAG,EAAC;gBAEjB,OAAO,CAAC,GAAG,CAAC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|
@@ -8,8 +8,11 @@ export declare class MembrsService {
|
|
|
8
8
|
_lsKey: string;
|
|
9
9
|
constructor(http: HttpClient, config: MembrsConfig);
|
|
10
10
|
reissue(token?: string): Promise<unknown>;
|
|
11
|
-
set token(token:
|
|
11
|
+
set token(token: string);
|
|
12
|
+
deleteToken(): void;
|
|
13
|
+
isLoggedIn(): boolean;
|
|
12
14
|
get profile(): any;
|
|
15
|
+
get token(): string;
|
|
13
16
|
get admin(): boolean;
|
|
14
17
|
logout(): Promise<unknown>;
|
|
15
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"__symbolic":"module","version":4,"metadata":{"MembrsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":18,"character":41},"arguments":[{"__symbolic":"reference","name":"ɵa"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":18,"character":28},{"__symbolic":"reference","name":"ɵb"}]}],"reissue":[{"__symbolic":"method"}],"logout":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}},"validateResolve":{"token":"reissue","deps":[{"__symbolic":"reference","module":"@uirouter/angular","name":"Transition","line":17,"character":12},{"__symbolic":"reference","module":"@uirouter/angular","name":"UIRouter","line":17,"character":24},{"__symbolic":"reference","name":"MembrsService"},{"__symbolic":"reference","name":"ɵa"}],"resolveFn":{"__symbolic":"reference","name":"validateResolveFn"}},"reissueResolve":{"token":"reissue","deps":[{"__symbolic":"reference","module":"@uirouter/angular","name":"Transition","line":23,"character":10},{"__symbolic":"reference","module":"@uirouter/angular","name":"UIRouter","line":23,"character":22},{"__symbolic":"reference","name":"MembrsService"},{"__symbolic":"reference","name":"ɵa"}],"resolveFn":{"__symbolic":"reference","name":"reissueResolveFn"}},"reissueState":{"name":"reissue","url":"/reissue?token","views":{},"resolve":[{"__symbolic":"reference","name":"reissueResolve"}]},"reissueResolveFn":{"__symbolic":"function","parameters":["transition","router","membrsService","membrsConfig"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"Promise"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","line":39,"character":23,"module":"./lib/membrs.module"}]}},"validateResolveFn":{"__symbolic":"function","parameters":["transition","router","membrsService","membrsConfig"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"Promise"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","line":59,"character":21,"module":"./lib/membrs.module"}]}},"jwtOptionsFactory":{"__symbolic":"function"},"STATES":[{"__symbolic":"reference","name":"reissueState"}],"MembrsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":93,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":95,"character":4},{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClientModule","line":96,"character":4},{"__symbolic":"reference","module":"@auth0/angular-jwt","name":"JwtModule","line":97,"character":4}]}]}],"members":{}},"retrieveToken":{"__symbolic":"function"},"TokenInterceptor":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":12,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"intercept":[{"__symbolic":"method"}]}},"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":7,"character":39},"arguments":["MembrsConfig"]},"ɵb":{"__symbolic":"interface"}},"origins":{"MembrsService":"./lib/membrs.service","validateResolve":"./lib/membrs.module","reissueResolve":"./lib/membrs.module","reissueState":"./lib/membrs.module","reissueResolveFn":"./lib/membrs.module","validateResolveFn":"./lib/membrs.module","jwtOptionsFactory":"./lib/membrs.module","STATES":"./lib/membrs.module","MembrsModule":"./lib/membrs.module","retrieveToken":"./lib/token","TokenInterceptor":"./lib/auth.interceptor","ɵa":"./lib/config.service","ɵb":"./lib/config.interface"},"importAs":"@nakedcreativity/membrs-angular-helper"}
|
|
1
|
+
{"__symbolic":"module","version":4,"metadata":{"MembrsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":18,"character":41},"arguments":[{"__symbolic":"reference","name":"ɵa"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":18,"character":28},{"__symbolic":"reference","name":"ɵb"}]}],"reissue":[{"__symbolic":"method"}],"deleteToken":[{"__symbolic":"method"}],"isLoggedIn":[{"__symbolic":"method"}],"logout":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}},"validateResolve":{"token":"reissue","deps":[{"__symbolic":"reference","module":"@uirouter/angular","name":"Transition","line":17,"character":12},{"__symbolic":"reference","module":"@uirouter/angular","name":"UIRouter","line":17,"character":24},{"__symbolic":"reference","name":"MembrsService"},{"__symbolic":"reference","name":"ɵa"}],"resolveFn":{"__symbolic":"reference","name":"validateResolveFn"}},"reissueResolve":{"token":"reissue","deps":[{"__symbolic":"reference","module":"@uirouter/angular","name":"Transition","line":23,"character":10},{"__symbolic":"reference","module":"@uirouter/angular","name":"UIRouter","line":23,"character":22},{"__symbolic":"reference","name":"MembrsService"},{"__symbolic":"reference","name":"ɵa"}],"resolveFn":{"__symbolic":"reference","name":"reissueResolveFn"}},"reissueState":{"name":"reissue","url":"/reissue?token","views":{},"resolve":[{"__symbolic":"reference","name":"reissueResolve"}]},"reissueResolveFn":{"__symbolic":"function","parameters":["transition","router","membrsService","membrsConfig"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"Promise"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","line":39,"character":23,"module":"./lib/membrs.module"}]}},"validateResolveFn":{"__symbolic":"function","parameters":["transition","router","membrsService","membrsConfig"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","name":"Promise"},"arguments":[{"__symbolic":"error","message":"Lambda not supported","line":59,"character":21,"module":"./lib/membrs.module"}]}},"jwtOptionsFactory":{"__symbolic":"function"},"STATES":[{"__symbolic":"reference","name":"reissueState"}],"MembrsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":93,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":95,"character":4},{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClientModule","line":96,"character":4},{"__symbolic":"reference","module":"@auth0/angular-jwt","name":"JwtModule","line":97,"character":4}]}]}],"members":{}},"retrieveToken":{"__symbolic":"function"},"TokenInterceptor":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":12,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"intercept":[{"__symbolic":"method"}]}},"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":7,"character":39},"arguments":["MembrsConfig"]},"ɵb":{"__symbolic":"interface"}},"origins":{"MembrsService":"./lib/membrs.service","validateResolve":"./lib/membrs.module","reissueResolve":"./lib/membrs.module","reissueState":"./lib/membrs.module","reissueResolveFn":"./lib/membrs.module","validateResolveFn":"./lib/membrs.module","jwtOptionsFactory":"./lib/membrs.module","STATES":"./lib/membrs.module","MembrsModule":"./lib/membrs.module","retrieveToken":"./lib/token","TokenInterceptor":"./lib/auth.interceptor","ɵa":"./lib/config.service","ɵb":"./lib/config.interface"},"importAs":"@nakedcreativity/membrs-angular-helper"}
|