DEV Community

What I learned on my own | Implementing JWT Authentication on SailsJS (v1)

Christophe El-Khoury on August 02, 2019

What this article will teach you: How to apply JWT Authentication in your SailsJS v1 backend. What this article will NOT teach you: How to cr...
Collapse
 
pragathyt95 profile image
pragathyt95

sails generate policy isAuthenticated

When i tried the above command, i got the following error:

error: No generator called policy found.
Did you mean sails generate api policy?

Tip: Want to use a custom or community generator?
Add it to your app's .sailsrc file under modules:
You can use a relative path:

"modules": {
  "policy": "./generators/policy"
}

Or the name of an NPM package:

"modules": {
  "policy": "sails-generate-react-component"
}

For help, see:
sailsjs.com/docs/concepts/extendin...

Collapse
 
christopheek profile image
Christophe El-Khoury • Edited

Thank you for the feedback!
At the time of this article, I was relying on Sails' Documentation, which currently takes us to a dead link. So it could be that it's changed. I've posted a comment with the updates

Thank you again!

Collapse
 
christopheek profile image
Christophe El-Khoury

As per @pragathyt95 , sails generate policy [policy-name] is not working. After trying to navigate to Sails' Documentation, it led me to a dead link, which could mean that it's no longer there.

The concept and everything else will still work as they should! All what you need to do is manually creating the policy inside api/policies/<policy_name.js>

Collapse
 
dominuskelvin profile image
Kelvin Omereshone

Great article, in reference to community, there is a brewing community for Sails at the moment and a platform that will be launching soon to teach Sails sailscasts.com

You can join the community by following this invite

discord.gg/gbJZuNm

We also have a blog dedicated to learning Sails things

blog.sailscasts.com

Collapse
 
dominuskelvin profile image
Kelvin Omereshone

By the way I wrote a LogRocket article on building a web API with Sails packed with user registration, JWT authentication, email verification and more.

Check it out if you are interested in that sort of thing :)
blog.logrocket.com/building-a-node...

Collapse
 
pragathyt95 profile image
pragathyt95

how to run this?

Collapse
 
christopheek profile image
Christophe El-Khoury

How to run what exactly?

Collapse
 
pragathyt95 profile image
pragathyt95 • Edited

i got it cleared thank u!

Thread Thread
 
christopheek profile image
Christophe El-Khoury

Alright Prathika. If there's anything else I can do, let me know!

Collapse
 
navicsteinr profile image
Navicstein Rotciv

Thanks for the article, being a sails fan I've been looking for a built in way of automatically handling JWT tokens, this really helps 😀

Collapse
 
christopheek profile image
Christophe El-Khoury

If there's anything else I can help you with, please let me know!

Collapse
 
plamenh profile image
Plamen Hristov

Hello, there! Thanks for the quick solution.

However, a crucial part is missing here - how do we generate the web tokens at the user level?

Collapse
 
christopheek profile image
Christophe El-Khoury

Hey there Plamen!

Unfortunately, this article does not have the purpose of teaching how JWT Tokens are generated.

If you'd like, and other people would too, I can create an article that serves that purpose! Let me know and help me get supporters for the purpose!

Collapse
 
navicsteinr profile image
Navicstein Rotciv

Thanks for this article it really helped!

Collapse
 
christopheek profile image
Christophe El-Khoury

If you need anything else make sure to ping me!