I am using Angular+Nest to develop a website. I have created a service(Angular) so that client can get user\'s information from server when project start up(the same as fresh).
If you really insist on this way (see comments), you can use Interceptors:
@Injectable()
export class GetUserInterceptor implements NestInterceptor {
constructor(private readonly authService: AuthService) {
}
async intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest()
const item = await this.authService.getByToken(/* extract me from headers*/)
request.user = item
return next.handle()
}
}
so AuthGuard is not needed.