Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda