1

I'm new to Adonis.js and have came across an issue when extending the official auth package. My application has requirements for two auth methods for different user types, one being email + password with tokens as the transport (easy enough), the other being able to take Firebase tokens and check against my users table to see if the phone number within the token is present.

Firebase tokens are simply JWTs which contain a phoneNumber property within the payload. I will already have the phone number for my users stored in the database, so I just need to query the phone number from the JWT before making a request in order to get the full user object.

I don't understand where to start with creating my own custom 'guard', the documentation has a guide on creating a custom user provider, but that seems to just be the methods for finding the users from the data source (not decoding the tokens, etc.). The actual code for interpreting the JWT is simple, I just don't know where to put it.

I know I could implement this using custom middleware instead of extending the auth package, but I think it might give me some benefit down the road to do it the proper way.

Adam Galloway
  • 71
  • 1
  • 5
  • 1
    Any development on this? I'm new to Adonis. Quite surprised that there is no mention of JWT in their documentation since that's a pretty common requirement. – jpmelanson Mar 16 '23 at 23:29
  • 1
    @jpmelanson Nope, sorry. Would recommend visiting the Adonis Discord for some advice on this, they are pretty helpful there. – Adam Galloway Mar 23 '23 at 22:18

0 Answers0