是否可以允许 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) 我目前正在将项目从 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 后,有哪些可能的解决方案可以访问我的文件信息?
我无法弄清楚如何使用 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 位数字。什么是替代解决方案?也许在转换为数字之前检查字符串长度?