Create and store JWT token on seeding users

Hey,

I am generating a JWT token when a user registers on the site using auth.authenticator('jwt').generate(user). That works fine.

I also want to be able to create tokens for each user when using the UserSeeder.

I’m not sure how I can approach this. Where do I get the auth object from? Any help would be appreciated.

What will you do with the tokens generated during the seeding process?

I don’t necessarily need the tokens during the seeding process. I tried registering a model hook, where afterCreate for each user a token is generated. I could not figure out from where to get the auth object.

Ok, so some context:-

I am building an Api secured with JWT.

For local testing with postman, I wanted to automate the token generation. Then a token would already be generated without having to manually register a user just to get the token.

I have now, actually found a way to work around it. So it’s not too important.

Just wondering, if that is something which would be possible to do.

You issue a token when someone authenticates themselves. So if a single user is authenticating 10times, they will get 10 tokens. In short, token is not associated to the creation of user it is associated to the event of login.

OK, i understand that.

Thanks for the help. Closing this now.