Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Proper way to use JWT auth in project

I know there are many similar questions, but I've still couldn't find answers to my questions.

  1. Is it a good idea to store refresh token inside db?
  2. Should I use redis or anything else for working with JWT? If yes - when?
  3. Is it a good idea to get all user data during token validating from db? For example I have such code:
  @UseGuards(JwtAuthGuard)
  public async create(
    @Req() request: RequestWithUserModel,
    @Body() createUserEnterpriseDto: CreateUserEnterpriseDto,
  ): Promise<UserEnterpriseEntity> {
    return await this.userEnterpriseService.create(
      request.user,
      createUserEnterpriseDto,
    );
  }

And I get user in my @UseGuards(). But If I'm going to use such approach to each endpoint it will create pressure to db, doesn't it? If so, are there the best ways to deal with it?

Thank you for answers!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

  1. If you are implementing OAuth yourself, then yes you have to store refresh token in you db. I would recommend using identity provider implementation like Auth0 instead of reinventing the wheel.

  2. Yes redis is a great choice for designing your auth service. This article does a good job in explaining the why aspect of it. https://redis.com/blog/json-web-tokens-jwt-are-dangerous-for-user-sessions/

  3. JWT is essentially a stateless way of authorization. Once your identity provider has issued a JWT, all that is needed for any authorised api is to test the validity of JWT. This means ensuring that JWT is not expired and is valid and has necessary roles. Validating against db for all authorised api's beats the purpose of a jwt

Hope this helps

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!