-
Notifications
You must be signed in to change notification settings - Fork 15
MongoDB #11
base: master
Are you sure you want to change the base?
MongoDB #11
Conversation
I @EduardoReolon, thanks! I have some questions before merging it:
You can obtain the payload you've set by doing this: await auth.use("jwt").authenticate();
const userPayload = auth.use("jwt").user!; |
I started using mongoose, then I realised it's not needed. I commented de lines e removed it from package.json
Idk if it is the right approach. In adonis 5 mongoose they stated the connection outside config, in start folder. So I kept the same structure, just sending the model already connected.
About this. authenticate method retrieves data from jwt_token and user tables. I think this approach kind of mess with the need of having a giant privateKey/publicKey. If the idea is to access database everytime, only refreshed token would be enough, isn't it? So that's what I did in my auth middleware:
And I call getUser user to get the user_id. If I need the full user, I pass the parameter "complete=true" But again. Let me know what u think, I'm not an expert. |
whoops my mistake, I looked at one commit
it looks weird to me - but ok. It's not so messy as I thought
The library already supports the recommended way of using JWT, that is, not storing in DB ( If you don't need that, then just set persistJwt to false, refresh token will be persisted instead 😄 |
I haven't realized that. I didn't look into this, by the name I thought that persistJwt = false was to have no token in DB at all. My mistake was assuming it instead of going into the codes. I think this is working any way. this or next week I'll test changing persistJwt to false, to see if it still fetchs the user, if not, it's gonna be perfect. Thanks. |
I implemented the non persistJwt with mongoDB. The same methods worded out for me. It fetches the user when authenticate. It's better if u want to deactivate the user at some point. But I prefer having a shorter jwt life time and don't depend on database at all. See if I need to pull a new request or u can access my last one |
Hello, Do I still have to do something? I've never done a pull request. |
I'm working on trying to merge it, don't worry, thanks for your work! |
Changed the least possible, to include persisted token in mongoDB.
I tested attempt, generate, loginViaRefreshToken and revoke. All worked well in mongoDB.
I also changed 2 functions to be public: getBearerToken and verifyToken. I use them because sometimes I only need the user_id, and I can take it from this functions.