Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "co-auther", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "", | ||
@@ -23,10 +23,14 @@ "main": "src/co-auther/co-auther.js", | ||
"license": "ISC", | ||
"peerDependencies": { | ||
"@angular/router": "^3.0.0-beta.2", | ||
"@angular/core": "^2.0.0-rc.4" | ||
}, | ||
"devDependencies": { | ||
"@angular/common": "2.0.0-rc.2", | ||
"@angular/compiler": "2.0.0-rc.2", | ||
"@angular/core": "2.0.0-rc.2", | ||
"@angular/http": "2.0.0-rc.2", | ||
"@angular/platform-browser": "2.0.0-rc.2", | ||
"@angular/platform-browser-dynamic": "2.0.0-rc.2", | ||
"@angular/router": "3.0.0-alpha.7", | ||
"@angular/common": "2.0.0-rc.4", | ||
"@angular/compiler": "2.0.0-rc.4", | ||
"@angular/core": "2.0.0-rc.4", | ||
"@angular/http": "2.0.0-rc.4", | ||
"@angular/platform-browser": "2.0.0-rc.4", | ||
"@angular/platform-browser-dynamic": "2.0.0-rc.4", | ||
"@angular/router": "3.0.0-beta.2", | ||
"bootstrap": "git+https://git@github.com/twbs/bootstrap.git#v4-dev", | ||
@@ -33,0 +37,0 @@ "es6-shim": "0.35.0", |
# co-auther | ||
Authentication related routing logics for an Angular 2 app like this: | ||
Authentication related routing logics for an app like this: | ||
@@ -14,2 +14,3 @@ - You are using JWT authentication | ||
- `npm install` | ||
- `npm run build` | ||
- `npm start` | ||
@@ -30,2 +31,4 @@ - open browser and navigate to page | ||
NOTE: The example is Angular 2 but co-auther can be used with any JS framework | ||
In your root component, load your API service and the CoAuther module. Then configure routes and initialize the CoAuther in the constructor of the component. Also expose the logout function from the CoAuther where you will use that: | ||
@@ -32,0 +35,0 @@ |
@@ -1,2 +0,2 @@ | ||
var port = 3000 | ||
var port = 3008 | ||
var staticDir = './' | ||
@@ -3,0 +3,0 @@ var express = require('express') |
@@ -18,4 +18,3 @@ "use strict"; | ||
var AppComponent = (function () { | ||
function AppComponent(router, apiService, coAutherNg2) { | ||
this.router = router; | ||
function AppComponent(apiService, coAutherNg2) { | ||
this.apiService = apiService; | ||
@@ -37,3 +36,3 @@ this.coAutherNg2 = coAutherNg2; | ||
}), | ||
__metadata('design:paramtypes', [router_1.Router, api_service_1.ApiService, co_auther_1.CoAutherNg2]) | ||
__metadata('design:paramtypes', [api_service_1.ApiService, co_auther_1.CoAutherNg2]) | ||
], AppComponent); | ||
@@ -40,0 +39,0 @@ return AppComponent; |
// Angular | ||
import {Component} from '@angular/core' | ||
import {ROUTER_DIRECTIVES, Router} from '@angular/router' | ||
import {ROUTER_DIRECTIVES} from '@angular/router' | ||
// Pages | ||
import {AuthenticateComponent} from './authenticate/authenticate.component' | ||
import {InitialRequestComponent} from './initial-request/initial-request.component' | ||
import {LoggedInComponent} from './logged-in/logged-in.component' | ||
// API and authentication services | ||
@@ -32,3 +27,2 @@ import {ApiService} from '../services/api-service' | ||
constructor ( | ||
private router: Router, | ||
private apiService: ApiService, | ||
@@ -35,0 +29,0 @@ private coAutherNg2: CoAutherNg2 |
@@ -6,3 +6,3 @@ "use strict"; | ||
var logged_in_routes_1 = require('./logged-in/logged-in.routes'); | ||
var co_auther_guard_1 = require('./co-auther.guard'); | ||
var co_auther_guard_1 = require('../co-auther.guard'); | ||
var dummy_component_1 = require('./dummy.component'); | ||
@@ -9,0 +9,0 @@ var routes = [ |
@@ -6,3 +6,3 @@ import {provideRouter, RouterConfig} from '@angular/router' | ||
import {LoggedInRoutes} from './logged-in/logged-in.routes' | ||
import {CoAutherGuard} from './co-auther.guard' | ||
import {CoAutherGuard} from '../co-auther.guard' | ||
@@ -9,0 +9,0 @@ import {DummyComponent} from './dummy.component' |
"use strict"; | ||
var authenticate_component_1 = require('./authenticate.component'); | ||
var co_auther_guard_1 = require('../co-auther.guard'); | ||
var co_auther_guard_1 = require('../../co-auther.guard'); | ||
exports.AuthenticateRoutes = [ | ||
@@ -5,0 +5,0 @@ { |
import {AuthenticateComponent} from './authenticate.component' | ||
import {CoAutherGuard} from '../co-auther.guard' | ||
import {CoAutherGuard} from '../../co-auther.guard' | ||
@@ -4,0 +4,0 @@ export const AuthenticateRoutes = [ |
"use strict"; | ||
var initial_request_component_1 = require('./initial-request.component'); | ||
var co_auther_guard_1 = require('../co-auther.guard'); | ||
var co_auther_guard_1 = require('../../co-auther.guard'); | ||
exports.InitialRequestRoutes = [ | ||
@@ -5,0 +5,0 @@ { |
import {InitialRequestComponent} from './initial-request.component' | ||
import {CoAutherGuard} from '../co-auther.guard' | ||
import {CoAutherGuard} from '../../co-auther.guard' | ||
@@ -4,0 +4,0 @@ export const InitialRequestRoutes = [ |
"use strict"; | ||
var logged_in_component_1 = require('./logged-in.component'); | ||
var co_auther_guard_1 = require('../co-auther.guard'); | ||
var co_auther_guard_1 = require('../../co-auther.guard'); | ||
var logged_in_child_component_1 = require('./logged-in-child.component'); | ||
@@ -5,0 +5,0 @@ var logged_in_child2_component_1 = require('./logged-in-child2.component'); |
import {LoggedInComponent} from './logged-in.component' | ||
import {CoAutherGuard} from '../co-auther.guard' | ||
import {CoAutherGuard} from '../../co-auther.guard' | ||
import {LoggedInChildComponent} from './logged-in-child.component' | ||
@@ -4,0 +4,0 @@ import {LoggedInChild2Component} from './logged-in-child2.component' |
@@ -14,2 +14,4 @@ "use strict"; | ||
var router_1 = require('@angular/router'); | ||
var core_routes_config_1 = require('../core-routes.config'); | ||
var co_auther_guard_1 = require('../co-auther.guard'); | ||
var ApiService = (function () { | ||
@@ -25,3 +27,3 @@ function ApiService(router) { | ||
localStorage.setItem('authData', data); | ||
_this.router.navigate(['/initial-request']); | ||
_this.router.navigate([core_routes_config_1.ROUTE_INITIAL_REQUEST]); | ||
resolve(data); | ||
@@ -36,8 +38,6 @@ }) | ||
ApiService.prototype.logout = function () { | ||
return new Promise(function (resolve, reject) { | ||
return mockRequest('Logout') | ||
.then(function () { | ||
localStorage.removeItem('authData'); | ||
window.location.reload(); | ||
}); | ||
return mockRequest('Logout') | ||
.then(function () { | ||
localStorage.removeItem('authData'); | ||
window.location.reload(); | ||
}); | ||
@@ -53,4 +53,5 @@ }; | ||
.then(function (data) { | ||
console.log('Initial request ok, route to "logged-in"'); | ||
_this.router.navigateByUrl('logged-in'); | ||
console.log('Initial request ok, route to intended route'); | ||
var finalDestination = co_auther_guard_1.memoryStateUrl || core_routes_config_1.ROUTE_LOGGED_IN; | ||
_this.router.navigateByUrl(finalDestination); | ||
resolve(data); | ||
@@ -61,3 +62,3 @@ }) | ||
localStorage.removeItem('authData'); | ||
_this.router.navigateByUrl('authenticate'); | ||
_this.router.navigateByUrl(core_routes_config_1.ROUTE_AUTHENTICATE); | ||
reject(err); | ||
@@ -64,0 +65,0 @@ }); |
// Simple mock example of an authentication API service | ||
import {Injectable} from '@angular/core' | ||
import {Router} from '@angular/router' | ||
import { | ||
ROUTE_AUTHENTICATE, | ||
ROUTE_INITIAL_REQUEST, | ||
ROUTE_LOGGED_IN | ||
} from '../core-routes.config' | ||
import {memoryStateUrl} from '../co-auther.guard' | ||
@@ -14,3 +20,3 @@ @Injectable() | ||
localStorage.setItem('authData', data) | ||
this.router.navigate(['/initial-request']) | ||
this.router.navigate([ROUTE_INITIAL_REQUEST]) | ||
resolve(data) | ||
@@ -26,9 +32,7 @@ }) | ||
public logout () { | ||
return new Promise((resolve, reject) => { | ||
return mockRequest('Logout') | ||
.then(() => { | ||
localStorage.removeItem('authData') | ||
window.location.reload() | ||
}) | ||
}) | ||
return mockRequest('Logout') | ||
.then(() => { | ||
localStorage.removeItem('authData') | ||
window.location.reload() | ||
}) | ||
} | ||
@@ -43,4 +47,5 @@ | ||
.then((data) => { | ||
console.log('Initial request ok, route to "logged-in"') | ||
this.router.navigateByUrl('logged-in') | ||
console.log('Initial request ok, route to intended route') | ||
let finalDestination = memoryStateUrl || ROUTE_LOGGED_IN | ||
this.router.navigateByUrl(finalDestination) | ||
resolve(data) | ||
@@ -51,7 +56,6 @@ }) | ||
localStorage.removeItem('authData') | ||
this.router.navigateByUrl('authenticate') | ||
this.router.navigateByUrl(ROUTE_AUTHENTICATE) | ||
reject(err) | ||
}) | ||
}) | ||
} | ||
@@ -58,0 +62,0 @@ } |
@@ -19,3 +19,2 @@ System.config({ | ||
'@angular/router': { defaultExtension: 'js', main: 'index.js' }, | ||
'@angular/router-deprecated': { defaultExtension: 'js', main: 'index.js' }, | ||
'@angular/testing': { defaultExtension: 'js', main: 'index.js' }, | ||
@@ -22,0 +21,0 @@ '@angular/upgrade': { defaultExtension: 'js', main: 'index.js' } |
@@ -20,3 +20,2 @@ declare var System | ||
'@angular/router': {defaultExtension: 'js', main: 'index.js'}, | ||
'@angular/router-deprecated': {defaultExtension: 'js', main: 'index.js'}, | ||
'@angular/testing': {defaultExtension: 'js', main: 'index.js'}, | ||
@@ -23,0 +22,0 @@ '@angular/upgrade': {defaultExtension: 'js', main: 'index.js'} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69658
84
1175
93
2