adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
196 stars 63 forks source link

Auth/Model example. #58

Closed mhingston closed 7 years ago

mhingston commented 7 years ago

Hi,

I'm new to Adonis and looking for an example of how to use JWT auth with Adonis 4x. I can see in the docs that I need to define a User model when using Lucid. I'm not sure how to represent the User model as the password hash function is implemented within the database, therefore I need to execute a raw query to call this function rather than just selecting from the table. In addition, passwords have expiry dates - how would I represent to the auth middleware that as well as checking that the email and hashed password match against a User, the password must also have not expired.

Thanks a lot.

RomainLanz commented 7 years ago

Hey @mhingston ! 👋

Have you actually run the install command?

$ adonis install @adonisjs/auth

This will create models, relations and middleware for you 👍

mhingston commented 7 years ago

Hi @RomainLanz, yes I created a new project with adonis new testapp. I tried re-running adonis install @adonisjs/auth but it errored as auth is already installed. I have a working example using basic auth and a sqlite database but still don't see how I can allow for my use case using Lucid models. Would it be better just writing my own auth middleware?

mhingston commented 7 years ago

I was able to resolve this by writing my own middleware, thanks again.