How can i to implement user session on microservices with nestjs?

Viewed 23

I have implemented user session with redis and passport, works fine when I use it on a monolith But I don't know how to implement it on a microservices, I want only put a guard in the api gateway and it send a request to validate user session to auth microservice This is my guard to validate user session:

@Injectable()
export class CookieAuthGuard implements CanActivate {
  async canActivate(context: ExecutionContext) {
    const request = context.switchToHttp().getRequest();

    return request.isAuthenticated();
  }
}

I don't know how to validate it on my provider to call it in my api gateway And I don't know how to put my login into the provider too, because i have a guard for that:

@Injectable()
export class LogInWithCredentialsGuard extends AuthGuard('local') {
  async canActivate(context: ExecutionContext): Promise<boolean> {
    await super.canActivate(context);

    const request = context.switchToHttp().getRequest();
    await super.logIn(request);

    return true;
  }
}

Any idea to implement validation of session working on the api gateway, and how to put login into provider?

Thanks!

0 Answers
Related