小编Jam*_*unt的帖子

使用Next-auth时从API返回错误信息

是否可以允许 next-auth 从 API 返回错误并从客户端传递它们?

例如,如果用户的电子邮件或密码不正确,API 将专门返回。在我们的移动应用程序上,这效果很好。尽管在网站上,我们使用的是 Next-auth。使用文档中的凭据示例,将返回值更改为对象会很棒。

import CredentialsProvider from "next-auth/providers/credentials"
providers: [
  CredentialsProvider({
    name: "Credentials",
 
    credentials: {
      username: { label: "Username", type: "text", placeholder: "jsmith" },
      password: {  label: "Password", type: "password" }
    },
    async authorize(credentials, req) {
      const user = { id: 1, name: "J Smith", email: "jsmith@example.com" }

      if (user) {
        // Any object returned will be saved in `user` property of the JWT
        return user
      } else {
        // Return an object that will pass …
Run Code Online (Sandbox Code Playgroud)

javascript next.js next-auth

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

使用 @aws-sdk/lib-storage 将文件上传到 AWS S3 时访问位置

我目前正在将项目从 SDK v2 升级到 V3,并且很难访问要上传到 S3 存储桶的文件的位置 URL。

目前,以下实现无法访问,location因为它不存在于AbortMultipartUploadCommandOutput响应类型中。

try {
    const x = new Upload({
      client: new S3Client({ region: "us-east-2" }),
      params: {
        Bucket: BUCKET_NAME,
        Key: filename.toString(),
        Body: buffer
      }
    })


    const response = await x.done()
    
    const locationUrl = response.location

    return locationUrl

  } catch (error) {
    console.log(error)
  }
Run Code Online (Sandbox Code Playgroud)

我一直在探索的另一个解决方案是使用PutObjectCommand.

const command = new PutObjectCommand({
    Bucket: BUCKET_NAME,
    Key: `${path}/${fileName}`,
    Body: fileContent,
    ContentType: "text/csv"
  })
Run Code Online (Sandbox Code Playgroud)

文件上传到 S3 后,有哪些可能的解决方案可以访问我的文件信息?

javascript amazon-s3 aws-sdk-js

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

Zod - 检查数字类型的位数

我无法弄清楚如何使用 Zod 检查数字中的位数。

由于我将字符串值转换为数字,因此我无法使用 min() 或 max() 来检查位数。

我在构建架构时尝试使用 lte() 和 gte() 以下内容:

export const MySchema = z.object({
  type1: z.coerce.string(),
  type2: z.coerce.string(),
  type4: z.coerce.number().lte(5).gte(5),
  type5: z.coerce.number()
})
Run Code Online (Sandbox Code Playgroud)

我的目标是将type4验证的固定长度限制为 5 位数字。什么是替代解决方案?也许在转换为数字之前检查字符串长度?

javascript typescript zod

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