Angular 2/5 JWT Authentication Example
To see a demo and further details go to http://jasonwatmore.com/post/2016/08/16/angular-2-jwt-authentication-example-tutorial
Angular 2/5 JWT Authentication Example
Home Page: http://jasonwatmore.com/post/2016/08/16/angular-2-jwt-authentication-example-tutorial
License: MIT License
Angular 2/5 JWT Authentication Example
To see a demo and further details go to http://jasonwatmore.com/post/2016/08/16/angular-2-jwt-authentication-example-tutorial
If I manually change the token value in stored in localstorage the UI still sees me as being logged in.
Any chance to update it to latest angular 2.rc.6 ? :)
Well, the page freezes on the loading screen. Checked everything and have no idea.
When i import localStorage is error.
npm install localStorage
by angular2 2.0.0
How to add angular-cli to this project? (sorry, i'm noob)
Please help me to add condition of signature expire in auth.guard. Here, we are only checking the token exist. I want to check whether our token expire and if expire, redirect to login page.
I'm trying to run this example as an Angular CLI app. It uses webpack by default instead of SystemJS. The bundle gets built with no errors, but I've got this error on the page:
metadata_resolver.js:508 Uncaught Error: Can't resolve all parameters for UserService: (Http, ?).
CompileMetadataResolver.getDependenciesMetadata @ metadata_resolver.js:508
CompileMetadataResolver.getTypeMetadata @ metadata_resolver.js:405
(anonymous function) @ metadata_resolver.js:552
CompileMetadataResolver.getProvidersMetadata @ metadata_resolver.js:532
CompileMetadataResolver.getNgModuleMetadata @ metadata_resolver.js:285
RuntimeCompiler._compileComponents @ runtime_compiler.js:126
RuntimeCompiler._compileModuleAndComponents @ runtime_compiler.js:64
RuntimeCompiler.compileModuleAsync @ runtime_compiler.js:55
PlatformRef_._bootstrapModuleWithZone @ application_ref.js:303
PlatformRef_.bootstrapModule @ application_ref.js:285
(anonymous function) @ main.ts:12
__webpack_require__ @ bootstrap 4990ebf…:52
(anonymous function) @ zone.js:1327
__webpack_require__ @ bootstrap 4990ebf…:52
webpackJsonpCallback @ bootstrap 4990ebf…:23
(anonymous function) @ main.bundle.js:1
I guess it has something to do with the second argument of UserService constructor, which is of type AuthenticationService: private authenticationService: AuthenticationService
.
@cornflourblue Can you please give a clue how to solve this error? I'm a noob in Angular and webpack seems a lot more easier (with literally no configuration) than SystemJS.
Hello,
When I try and run this on my machine (with npm start) I get the following error message:
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: tsc && concurrently "npm run tsc:w" "npm run lite"
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
npm ERR! This is most likely a problem with the angular2-jwt-authentication-example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc && concurrently "npm run tsc:w" "npm run lite"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-jwt-authentication-example
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls angular2-jwt-authentication-example
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\david\Angular2 Projects\angular2-jwt-authentication-example-master\npm-debug.log
I just downloaded the example as is from GitHub - is there something else I need to do to run it properly?
Implemented CanActivate to guard the routes, and navigating to /login if the user is not logged in, but i can see it is redirecting with POST request, which results to 404 error.
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router) { }
canActivate() {
console.log("canActivate : AuthGuard");
if (localStorage.getItem('currentUser')) {
// logged in so return true
return true;
}
// not logged in so redirect to login page
this.router.navigate(['/login']);
return false;
}
}
http://stackoverflow.com/questions/40393609/angular2-router-canactivate-is-redirecting-with-post-request
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.