小编Sam*_*e11的帖子

NestJS - AuthGuard 如何了解 Passport 策略?

当涉及到身份验证/授权过程时,我很难弄清楚 NestJS 和 PassportJS 的组合,而且我是一种在开发时不喜欢魔法的开发人员。

问题

基本上,我的目标是了解 AuthGuard 如何知道项目中正在实施的 Passport 策略,它可以是本地策略,也可以是任何其他策略,例如 JWT 策略。我有两个模块AuthModuleUserModule,这就是AuthService的样子:

@Injectable()
export class AuthService {
    constructor(private usersService: UsersService){}

    async validateUser(username: string, password: string): Promise<any> {
        const user = await this.usersService.findOne(username);

        if (user && user.password === password) {
            const {password, ...result} = user
            return result
        }
        return null
    }
}
Run Code Online (Sandbox Code Playgroud)

用户服务

import { Injectable } from '@nestjs/common';

export type User = any;

@Injectable()
export class UsersService {

    private readonly users = …
Run Code Online (Sandbox Code Playgroud)

node.js passport.js nestjs

7
推荐指数
1
解决办法
4996
查看次数

Next.js 11 - 图像优化在生产环境中不起作用

我对 Next.js 中的图像组件有一个小问题。我使用的是下一个11.0.1版本,在开发和本地环境中没有发现任何问题。图像正在优化,一切正常。然而,我和团队发现当网站部署到生产环境时,图像没有得到优化。我们正在使用亚马逊服务来做到这一点。

这是我的意思的证明:

当地环境:

On wide-screen (1024px width)
Rendered size:  50 x 50 px
File size:  1.3 kB
Run Code Online (Sandbox Code Playgroud)

生产环境:

On wide-screen (1024px width)
Rendered size:  512 x 512 px
File size:  41.5 kB
Run Code Online (Sandbox Code Playgroud)

当然,这并不是一个很大的区别,但我仍然想知道如何在生产环境中解决这个问题。我还添加了对项目本身的强烈依赖,因为我知道它将提高在页面上加载图像的性能。问题可能是亚马逊设置不正确吗?

Next.config.js

module.exports = {
  reactStrictMode: true,
  images: {
    domains: ['avatars.slack-edge.com'],
  },
};
Run Code Online (Sandbox Code Playgroud)

image amazon-web-services reactjs next.js nextjs-image

5
推荐指数
1
解决办法
1567
查看次数

Next.js - 我们可以在 GetStaticProps() 中调用自定义挂钩吗

我们有什么办法可以在getStaticProps()中使用自定义钩子这样做的原因是,我们使用 Contentful CMS 从Delivery API获取数据,并且我们更容易使用自定义挂钩来获取某些数据。

现在,当我们调用getStaticProps()函数中的useHomePageData时,我们在尝试使用简单的对象破坏来获取数据时会收到错误。

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 
1. You might have mismatching versions of React and the renderer (such as React DOM) 
2. You might be breaking the Rules of Hooks 
3. You might have more than one copy of React in the same app See …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js

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