我正在尝试按照本教程进行操作,并且正在努力将实现转换为 GraphQL。
本地策略.ts
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authenticationService: AuthenticationService) {
super();
}
async validate(email: string, password: string): Promise<any> {
const user = await this.authenticationService.getAuthenticatedUser(
email,
password,
);
if (!user) throw new UnauthorizedException();
return user;
}
}
Run Code Online (Sandbox Code Playgroud)
本地警卫.ts
@Injectable()
export class LogInWithCredentialsGuard extends AuthGuard('local') {
async canActivate(context: ExecutionContext): Promise<boolean> {
const ctx = GqlExecutionContext.create(context);
const { req } = ctx.getContext();
req.body = ctx.getArgs();
await super.canActivate(new ExecutionContextHost([req]));
await super.logIn(req);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
身份验证.type.ts
@InputType() …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个 Alert 类,如下所示:
@ObjectType()
export class Alert {
@Field()
status: 'error' | 'success' | 'warning' | 'info' | undefined
@Field(() => [String])
messages: string[];
}
Run Code Online (Sandbox Code Playgroud)
但是,它给了我以下错误消息:
错误:无法从 TypeScript 反射系统推断 GraphQL 类型。您需要为“警报”类的“状态”提供显式类型。
我只想保留第一个点之前的单词:
user.entity.ts
Run Code Online (Sandbox Code Playgroud)
当前代码:
${TM_FILENAME_BASE/([^.]+)/${1:/upcase}/}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这只是转换了第一部分,而不是把它分开:
USER.entity
Run Code Online (Sandbox Code Playgroud)