小编sto*_*nie的帖子

Google Identity Platform 可用的 MFA 程序

Google Identity Platform 文档仅提到通过短信进行 MFA。像 TOTP 这样的程序真的不支持吗?这是近期的计划吗?

对于复杂的企业应用程序,出于安全原因和短信成本的考虑,我认为这是必要的。

google-cloud-identity

8
推荐指数
0
解决办法
275
查看次数

TypeORM 关系:只有 ID 而不是整个实例

根据文档,在 TypeORM 中,关系定义如下:用户只有一个配置文件。

import {Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn} from "typeorm";
import {Profile} from "./Profile";

@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @OneToOne(type => Profile)
    @JoinColumn()
    profile: Profile;

}
Run Code Online (Sandbox Code Playgroud)

问题

创建新用户时,为什么我必须传递实体的完整实例(profile: Profile)而不是 - 像往常一样 - 只有一个 ID?像这样:

@OneToOne(type => Profile)
    @JoinColumn()
    profileId: number;
Run Code Online (Sandbox Code Playgroud)

没有别的办法吗?

如果您必须对 4 个外键进行 4 次查询以获取相应的实例而不是 ID,则此过程会导致大量不必要的开销。

我将非常感谢帮助解决这个问题!

foreign-keys relationship typeorm

4
推荐指数
1
解决办法
2666
查看次数

NestJS + Mongoose + GraphQL:“填充”不起作用

感谢伟大的框架!

我将 mongoose 与 GraphQL 结合使用并遇到以下问题:

如果我想用 来解析存储在用户的数组“参数”中的 ObjectID populate,在 GraphQL 中我会得到一个空参数数组作为答案的用户。

ArgumentSchema我怀疑定义引用(MongoDB 模式的名称)或填充arguments(用户属性的名称)时出现错误。这是如何正确工作的?

论证模式

export const ArgumentSchema = new mongoose.Schema({
  argument: { type: String, required: true },
  userId: { type: String, required: true },
  username: { type: String, required: true },
});
Run Code Online (Sandbox Code Playgroud)

用户模式

export const UserSchema = new mongoose.Schema({
  username: { type: String, required: true },
  email: { type: String, required: true },
  age: { type: Number, required: true },
  arguments: { type: [mongoose.Schema.Types.ObjectId], required: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb mongoose-populate graphql nestjs

3
推荐指数
1
解决办法
3070
查看次数

带有守卫/装饰器的身份验证和角色:如何传递用户对象?

在 Guards/Decorators 的帮助下,我尝试首先检查 JWT,然后检查用户拥有的角色。

我已阅读有关身份验证、守卫和装饰器的文档并了解它们背​​后的原理。

但是,我无法做的是以某种方式使 JWT-Guard 中经过身份验证的用户可供 Roles-Guards 使用。

在我发现的每个例子中,正是我感兴趣的这部分被跳过/遗漏了......

感谢每一个提示!

这是我最近的尝试:

jwt.strategy.ts

import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { JwtPayload } from './jwt.model';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor() {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      passReqToCallback: true,
      ignoreExpiration: false,
      secretOrKey: '0000',
      expiresIn: '3 days'
    });
  }

  async validate(payload: JwtPayload) {
    return {
      id: payload.id,
      email: payload.email,
      username: payload.username
    };
  }
}
Run Code Online (Sandbox Code Playgroud)

角色.guard.ts

import { …
Run Code Online (Sandbox Code Playgroud)

nestjs

2
推荐指数
1
解决办法
8452
查看次数

TypeORM:仅加载某些指定字段的关系

尽管进行了大量研究和反复试验,但不幸的是,我还没有针对以下用例的优雅解决方案:用户有多个帖子,这些帖子被正确实现为一对多关系。我想向用户加载他的所有帖子,但不是帖子的所有属性,而是仅加载某些属性

方法一:查找

await this.usersRepository.find({relations: ['posts']});
Run Code Online (Sandbox Code Playgroud)

这里我无法在任何地方定义相应的选择限制。

方法 2:查询生成器

await this.usersRepository.createQueryBuilder('user')
.leftJoinAndSelect('user.posts', 'posts').select('posts.title').getMany();
Run Code Online (Sandbox Code Playgroud)

这里我假设定义了限制,但选择似乎仅指用户。

我错过了什么吗?或者对于我的用例没有预期的解决方案?

我将非常感谢您的帮助,谢谢大家!

TypeORM 版本 0.2.22

database-relations typeorm

2
推荐指数
1
解决办法
2万
查看次数